mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-30 20:52:30 +02:00
Fixed build issue with Mac OSX, which don't support std::chrono::monotonic_clock.
This commit is contained in:
parent
c939dec26a
commit
5f644b1b04
2 changed files with 39 additions and 31 deletions
26
Log.cpp
26
Log.cpp
|
@ -8,13 +8,13 @@ static const char * g_LogLevelStr[eNumLogLevels] =
|
|||
"error", // eLogError
|
||||
"warn", // eLogWarning
|
||||
"info", // eLogInfo
|
||||
"debug" // eLogDebug
|
||||
"debug" // eLogDebug
|
||||
};
|
||||
|
||||
void LogMsg::Process()
|
||||
{
|
||||
auto& output = (log && log->GetLogStream ()) ? *log->GetLogStream () : std::cerr;
|
||||
if (log)
|
||||
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 ();
|
||||
|
@ -24,16 +24,20 @@ void LogMsg::Process()
|
|||
|
||||
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 !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;
|
||||
}
|
||||
|
||||
|
@ -50,13 +54,13 @@ void Log::SetLogFile (const std::string& fullFilePath)
|
|||
{
|
||||
SetLogStream (logFile);
|
||||
LogPrint("Logging to file ", fullFilePath, " enabled.");
|
||||
}
|
||||
}
|
||||
else
|
||||
delete logFile;
|
||||
}
|
||||
|
||||
void Log::SetLogStream (std::ostream * logStream)
|
||||
{
|
||||
if (m_LogStream) delete m_LogStream;
|
||||
if (m_LogStream) delete m_LogStream;
|
||||
m_LogStream = logStream;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue