From 05c2adeefd12111a9b935df8c86c5ca449e144ac Mon Sep 17 00:00:00 2001 From: Darknet Villain Date: Mon, 18 Sep 2017 15:24:53 -0400 Subject: [PATCH 1/3] fix typo --- build/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 "---------------------------------------") From d500fe66fd572899c4b4a99bc577d63c1b538ff5 Mon Sep 17 00:00:00 2001 From: Darknet Villain Date: Mon, 18 Sep 2017 18:49:03 -0400 Subject: [PATCH 2/3] Add option logclftime=true for writing full date and time to logs --- libi2pd/Config.cpp | 1 + libi2pd/Log.cpp | 7 +++++-- libi2pd/Log.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) 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; From 681810ea38181eb81bcd12f182aa257736c709bd Mon Sep 17 00:00:00 2001 From: Darknet Villain Date: Tue, 19 Sep 2017 19:46:28 -0400 Subject: [PATCH 3/3] Use setter method for m_TimeFormat, set time format in Daemon.cpp instead of Log.cpp --- daemon/Daemon.cpp | 4 ++++ libi2pd/Log.cpp | 3 --- libi2pd/Log.h | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) 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/Log.cpp b/libi2pd/Log.cpp index 0430ed57..8ae417c2 100644 --- a/libi2pd/Log.cpp +++ b/libi2pd/Log.cpp @@ -7,7 +7,6 @@ */ #include "Log.h" -#include "Config.h" namespace i2p { namespace log { @@ -74,8 +73,6 @@ 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)); } } diff --git a/libi2pd/Log.h b/libi2pd/Log.h index e3ce65cd..bec741a8 100644 --- a/libi2pd/Log.h +++ b/libi2pd/Log.h @@ -108,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