mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-30 12:47:48 +02:00
Merge remote-tracking branch 'github/master'
Conflicts: Log.cpp Log.h
This commit is contained in:
commit
6f569f5334
2 changed files with 101 additions and 93 deletions
68
Log.cpp
68
Log.cpp
|
@ -5,36 +5,40 @@ Log * g_Log = nullptr;
|
|||
|
||||
static const char * g_LogLevelStr[eNumLogLevels] =
|
||||
{
|
||||
"error", // eLogError
|
||||
"warn", // eLogWarning
|
||||
"info", // eLogInfo
|
||||
"debug" // eLogDebug
|
||||
"error", // eLogError
|
||||
"warn", // eLogWarning
|
||||
"info", // eLogInfo
|
||||
"debug" // eLogDebug
|
||||
};
|
||||
|
||||
void LogMsg::Process()
|
||||
{
|
||||
auto& output = (log && log->GetLogStream ()) ? *log->GetLogStream () : std::cerr;
|
||||
if (log)
|
||||
output << log->GetTimestamp ();
|
||||
else
|
||||
output << boost::posix_time::second_clock::local_time().time_of_day ();
|
||||
output << "/" << g_LogLevelStr[level] << " - ";
|
||||
output << s.str();
|
||||
auto& output = (log && log->GetLogStream ()) ? *log->GetLogStream () : std::cerr;
|
||||
if (log)
|
||||
output << log->GetTimestamp ();
|
||||
else
|
||||
output << boost::posix_time::second_clock::local_time().time_of_day ();
|
||||
output << "/" << g_LogLevelStr[level] << " - ";
|
||||
output << s.str();
|
||||
}
|
||||
|
||||
const std::string& Log::GetTimestamp ()
|
||||
{
|
||||
#if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6)
|
||||
auto ts = std::chrono::monotonic_clock::now ();
|
||||
#else
|
||||
auto ts = std::chrono::steady_clock::now ();
|
||||
#endif
|
||||
if (ts > m_LastTimestampUpdate + std::chrono::milliseconds (500)) // 0.5 second
|
||||
{
|
||||
m_LastTimestampUpdate = ts;
|
||||
m_Timestamp = boost::posix_time::to_simple_string (boost::posix_time::second_clock::local_time().time_of_day ());
|
||||
}
|
||||
return m_Timestamp;
|
||||
#if !defined(__APPLE__)
|
||||
#if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6) && !defined(__APPLE__)
|
||||
auto ts = std::chrono::monotonic_clock::now ();
|
||||
#else
|
||||
auto ts = std::chrono::steady_clock::now ();
|
||||
#endif
|
||||
#else
|
||||
auto ts = std::chrono::steady_clock::now ();
|
||||
#endif
|
||||
if (ts > m_LastTimestampUpdate + std::chrono::milliseconds (500)) // 0.5 second
|
||||
{
|
||||
m_LastTimestampUpdate = ts;
|
||||
m_Timestamp = boost::posix_time::to_simple_string (boost::posix_time::second_clock::local_time().time_of_day ());
|
||||
}
|
||||
return m_Timestamp;
|
||||
}
|
||||
|
||||
void Log::Flush ()
|
||||
|
@ -45,18 +49,18 @@ void Log::Flush ()
|
|||
|
||||
void Log::SetLogFile (const std::string& fullFilePath)
|
||||
{
|
||||
auto logFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
||||
if (logFile->is_open ())
|
||||
{
|
||||
SetLogStream (logFile);
|
||||
LogPrint("Logging to file ", fullFilePath, " enabled.");
|
||||
}
|
||||
else
|
||||
delete logFile;
|
||||
auto logFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
||||
if (logFile->is_open ())
|
||||
{
|
||||
SetLogStream (logFile);
|
||||
LogPrint("Logging to file ", fullFilePath, " enabled.");
|
||||
}
|
||||
else
|
||||
delete logFile;
|
||||
}
|
||||
|
||||
void Log::SetLogStream (std::ostream * logStream)
|
||||
{
|
||||
if (m_LogStream) delete m_LogStream;
|
||||
m_LogStream = logStream;
|
||||
if (m_LogStream) delete m_LogStream;
|
||||
m_LogStream = logStream;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue