|
|
|
@ -10,6 +10,10 @@
@@ -10,6 +10,10 @@
|
|
|
|
|
#include <memory> |
|
|
|
|
#include "Queue.h" |
|
|
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
#include <syslog.h> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
enum LogLevel |
|
|
|
|
{ |
|
|
|
|
eLogError = 0, |
|
|
|
@ -45,14 +49,19 @@ class Log: public i2p::util::MsgQueue<LogMsg>
@@ -45,14 +49,19 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|
|
|
|
std::shared_ptr<std::ostream> GetLogStream () const { return m_LogStream; }; |
|
|
|
|
const std::string& GetTimestamp (); |
|
|
|
|
LogLevel GetLogLevel () { return m_MinLevel; }; |
|
|
|
|
const std::string& GetFullFilePath () const { return m_FullFilePath; }; |
|
|
|
|
|
|
|
|
|
const std::string& GetFullFilePath () const { return m_FullFilePath; }; |
|
|
|
|
/** start logging to syslog */ |
|
|
|
|
void StartSyslog(const std::string & ident, const int facility); |
|
|
|
|
/** stop logging to syslog */ |
|
|
|
|
void StopSyslog(); |
|
|
|
|
/** are we logging to syslog right now? */ |
|
|
|
|
bool SyslogEnabled(); |
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
void Flush (); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string m_FullFilePath; // empty if stream
|
|
|
|
|
std::shared_ptr<std::ostream> m_LogStream; |
|
|
|
|
enum LogLevel m_MinLevel; |
|
|
|
@ -61,7 +70,8 @@ class Log: public i2p::util::MsgQueue<LogMsg>
@@ -61,7 +70,8 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|
|
|
|
std::chrono::monotonic_clock::time_point m_LastTimestampUpdate; |
|
|
|
|
#else |
|
|
|
|
std::chrono::steady_clock::time_point m_LastTimestampUpdate; |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
std::string m_Ident; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
extern Log * g_Log; |
|
|
|
@ -116,6 +126,20 @@ inline bool IsLogToFile ()
@@ -116,6 +126,20 @@ inline bool IsLogToFile ()
|
|
|
|
|
return g_Log ? !g_Log->GetFullFilePath ().empty () : false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void StartSyslog() |
|
|
|
|
{ |
|
|
|
|
StartLog(""); |
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
g_Log->StartSyslog("i2pd", LOG_USER); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void StopSyslog() |
|
|
|
|
{ |
|
|
|
|
if(g_Log) |
|
|
|
|
g_Log->StopSyslog(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<typename TValue> |
|
|
|
|
void LogPrint (std::stringstream& s, TValue arg) |
|
|
|
|
{ |
|
|
|
|