diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index f8985010..26f09696 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -38,6 +38,7 @@ namespace config { ("log", value()->default_value(""), "Logs destination: stdout, file, syslog (stdout if not set)") ("logfile", value()->default_value(""), "Path to logfile (stdout if not set, autodetect if daemon)") ("loglevel", value()->default_value("info"), "Set the minimal level of log messages (debug, info, warn, error)") + ("logclftime", value()->default_value(false), "Write full CLF-formatted date and time to log (default: write only time)") ("family", value()->default_value(""), "Specify a family, router belongs to") ("datadir", value()->default_value(""), "Path to storage of i2pd data (RI, keys, peer profiles, ...)") ("host", value()->default_value("0.0.0.0"), "External IP") diff --git a/libi2pd/Log.cpp b/libi2pd/Log.cpp index 7cd4205e..0430ed57 100644 --- a/libi2pd/Log.cpp +++ b/libi2pd/Log.cpp @@ -7,6 +7,7 @@ */ #include "Log.h" +#include "Config.h" namespace i2p { namespace log { @@ -58,7 +59,7 @@ namespace log { Log::Log(): m_Destination(eLogStdout), m_MinLevel(eLogInfo), - m_LogStream (nullptr), m_Logfile(""), m_HasColors(true), + m_LogStream (nullptr), m_Logfile(""), m_HasColors(true), m_TimeFormat("%H:%M:%S"), m_IsRunning (false), m_Thread (nullptr) { } @@ -73,6 +74,8 @@ namespace log { if (!m_IsRunning) { m_IsRunning = true; + bool logclftime; i2p::config::GetOption("logclftime", logclftime); + if (logclftime) m_TimeFormat = "[%d/%b/%Y:%H:%M:%S %z]"; m_Thread = new std::thread (std::bind (&Log::Run, this)); } } @@ -118,7 +121,7 @@ namespace log { const char * Log::TimeAsString(std::time_t t) { if (t != m_LastTimestamp) { - strftime(m_LastDateTime, sizeof(m_LastDateTime), "%H:%M:%S", localtime(&t)); + strftime(m_LastDateTime, sizeof(m_LastDateTime), m_TimeFormat.c_str(), localtime(&t)); m_LastTimestamp = t; } return m_LastDateTime; diff --git a/libi2pd/Log.h b/libi2pd/Log.h index 1d02a845..e3ce65cd 100644 --- a/libi2pd/Log.h +++ b/libi2pd/Log.h @@ -58,6 +58,7 @@ namespace log { char m_LastDateTime[64]; i2p::util::Queue > m_Queue; bool m_HasColors; + std::string m_TimeFormat; volatile bool m_IsRunning; std::thread * m_Thread;