Browse Source

Add option logclftime=true for writing full date and time to logs

pull/961/head
Darknet Villain 7 years ago
parent
commit
d500fe66fd
  1. 1
      libi2pd/Config.cpp
  2. 7
      libi2pd/Log.cpp
  3. 1
      libi2pd/Log.h

1
libi2pd/Config.cpp

@ -38,6 +38,7 @@ namespace config { @@ -38,6 +38,7 @@ namespace config {
("log", value<std::string>()->default_value(""), "Logs destination: stdout, file, syslog (stdout if not set)")
("logfile", value<std::string>()->default_value(""), "Path to logfile (stdout if not set, autodetect if daemon)")
("loglevel", value<std::string>()->default_value("info"), "Set the minimal level of log messages (debug, info, warn, error)")
("logclftime", value<bool>()->default_value(false), "Write full CLF-formatted date and time to log (default: write only time)")
("family", value<std::string>()->default_value(""), "Specify a family, router belongs to")
("datadir", value<std::string>()->default_value(""), "Path to storage of i2pd data (RI, keys, peer profiles, ...)")
("host", value<std::string>()->default_value("0.0.0.0"), "External IP")

7
libi2pd/Log.cpp

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
*/
#include "Log.h"
#include "Config.h"
namespace i2p {
namespace log {
@ -58,7 +59,7 @@ 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 { @@ -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 { @@ -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;

1
libi2pd/Log.h

@ -58,6 +58,7 @@ namespace log { @@ -58,6 +58,7 @@ namespace log {
char m_LastDateTime[64];
i2p::util::Queue<std::shared_ptr<LogMsg> > m_Queue;
bool m_HasColors;
std::string m_TimeFormat;
volatile bool m_IsRunning;
std::thread * m_Thread;

Loading…
Cancel
Save