diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 06e1c24f..d966ab2f 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -393,7 +393,7 @@ message(STATUS " UPnP : ${WITH_UPNP}") message(STATUS " PCH : ${WITH_PCH}") message(STATUS " MESHNET : ${WITH_MESHNET}") message(STATUS " ADDRSANITIZER : ${WITH_ADDRSANITIZER}") -message(STATUS " THEADSANITIZER : ${WITH_THREADSANITIZER}") +message(STATUS " THREADSANITIZER : ${WITH_THREADSANITIZER}") message(STATUS " I2LUA : ${WITH_I2LUA}") message(STATUS " WEBSOCKETS : ${WITH_WEBSOCKETS}") message(STATUS "---------------------------------------") diff --git a/daemon/Daemon.cpp b/daemon/Daemon.cpp index 32595390..658bf011 100644 --- a/daemon/Daemon.cpp +++ b/daemon/Daemon.cpp @@ -94,8 +94,12 @@ namespace i2p std::string logs = ""; i2p::config::GetOption("log", logs); std::string logfile = ""; i2p::config::GetOption("logfile", logfile); std::string loglevel = ""; i2p::config::GetOption("loglevel", loglevel); + bool logclftime; i2p::config::GetOption("logclftime", logclftime); /* setup logging */ + if (logclftime) + i2p::log::Logger().SetTimeFormat ("[%d/%b/%Y:%H:%M:%S %z]"); + if (isDaemon && (logs == "" || logs == "stdout")) logs = "file"; 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..8ae417c2 100644 --- a/libi2pd/Log.cpp +++ b/libi2pd/Log.cpp @@ -58,7 +58,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) { } @@ -118,7 +118,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..bec741a8 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; @@ -107,6 +108,12 @@ namespace log { */ void SendTo (std::shared_ptr os); + /** + * @brief Sets format for timestamps in log + * @param format String with timestamp format + */ + void SetTimeFormat (std::string format) { m_TimeFormat = format; }; + #ifndef _WIN32 /** * @brief Sets log destination to syslog