|
|
|
@ -7,6 +7,7 @@
@@ -7,6 +7,7 @@
|
|
|
|
|
#include <fstream> |
|
|
|
|
#include <functional> |
|
|
|
|
#include <chrono> |
|
|
|
|
#include <memory> |
|
|
|
|
#include "Queue.h" |
|
|
|
|
|
|
|
|
|
enum LogLevel |
|
|
|
@ -34,13 +35,14 @@ class Log: public i2p::util::MsgQueue<LogMsg>
@@ -34,13 +35,14 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
Log (): m_LogStream (nullptr) { SetOnEmpty (std::bind (&Log::Flush, this)); }; |
|
|
|
|
~Log () { delete m_LogStream; }; |
|
|
|
|
Log () { SetOnEmpty (std::bind (&Log::Flush, this)); }; |
|
|
|
|
~Log () {}; |
|
|
|
|
|
|
|
|
|
void SetLogFile (const std::string& fullFilePath); |
|
|
|
|
void ReopenLogFile (); |
|
|
|
|
void SetLogLevel (const std::string& level); |
|
|
|
|
void SetLogStream (std::ostream * logStream); |
|
|
|
|
std::ostream * GetLogStream () const { return m_LogStream; }; |
|
|
|
|
void SetLogStream (std::shared_ptr<std::ostream> logStream); |
|
|
|
|
std::shared_ptr<std::ostream> GetLogStream () const { return m_LogStream; }; |
|
|
|
|
const std::string& GetTimestamp (); |
|
|
|
|
LogLevel GetLogLevel () { return m_MinLevel; }; |
|
|
|
|
|
|
|
|
@ -50,7 +52,8 @@ class Log: public i2p::util::MsgQueue<LogMsg>
@@ -50,7 +52,8 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
std::ostream * m_LogStream; |
|
|
|
|
std::string m_FullFilePath; // empty if stream
|
|
|
|
|
std::shared_ptr<std::ostream> m_LogStream; |
|
|
|
|
enum LogLevel m_MinLevel; |
|
|
|
|
std::string m_Timestamp; |
|
|
|
|
#if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6) && !defined(__clang__) // gcc 4.6
|
|
|
|
@ -73,7 +76,7 @@ inline void StartLog (const std::string& fullFilePath)
@@ -73,7 +76,7 @@ inline void StartLog (const std::string& fullFilePath)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void StartLog (std::ostream * s) |
|
|
|
|
inline void StartLog (std::shared_ptr<std::ostream> s) |
|
|
|
|
{ |
|
|
|
|
if (!g_Log) |
|
|
|
|
{ |
|
|
|
@ -101,6 +104,12 @@ inline void SetLogLevel (const std::string& level)
@@ -101,6 +104,12 @@ inline void SetLogLevel (const std::string& level)
|
|
|
|
|
g_Log->SetLogLevel(level); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void ReopenLogFile () |
|
|
|
|
{ |
|
|
|
|
if (g_Log) |
|
|
|
|
g_Log->ReopenLogFile (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<typename TValue> |
|
|
|
|
void LogPrint (std::stringstream& s, TValue arg) |
|
|
|
|
{ |
|
|
|
|