mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
Add option logclftime=true for writing full date and time to logs
This commit is contained in:
parent
05c2adeefd
commit
d500fe66fd
|
@ -38,6 +38,7 @@ namespace config {
|
||||||
("log", value<std::string>()->default_value(""), "Logs destination: stdout, file, syslog (stdout if not set)")
|
("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)")
|
("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)")
|
("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")
|
("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, ...)")
|
("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")
|
("host", value<std::string>()->default_value("0.0.0.0"), "External IP")
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
namespace i2p {
|
namespace i2p {
|
||||||
namespace log {
|
namespace log {
|
||||||
|
@ -58,7 +59,7 @@ namespace log {
|
||||||
|
|
||||||
Log::Log():
|
Log::Log():
|
||||||
m_Destination(eLogStdout), m_MinLevel(eLogInfo),
|
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)
|
m_IsRunning (false), m_Thread (nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -73,6 +74,8 @@ namespace log {
|
||||||
if (!m_IsRunning)
|
if (!m_IsRunning)
|
||||||
{
|
{
|
||||||
m_IsRunning = true;
|
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));
|
m_Thread = new std::thread (std::bind (&Log::Run, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +121,7 @@ namespace log {
|
||||||
|
|
||||||
const char * Log::TimeAsString(std::time_t t) {
|
const char * Log::TimeAsString(std::time_t t) {
|
||||||
if (t != m_LastTimestamp) {
|
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;
|
m_LastTimestamp = t;
|
||||||
}
|
}
|
||||||
return m_LastDateTime;
|
return m_LastDateTime;
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace log {
|
||||||
char m_LastDateTime[64];
|
char m_LastDateTime[64];
|
||||||
i2p::util::Queue<std::shared_ptr<LogMsg> > m_Queue;
|
i2p::util::Queue<std::shared_ptr<LogMsg> > m_Queue;
|
||||||
bool m_HasColors;
|
bool m_HasColors;
|
||||||
|
std::string m_TimeFormat;
|
||||||
volatile bool m_IsRunning;
|
volatile bool m_IsRunning;
|
||||||
std::thread * m_Thread;
|
std::thread * m_Thread;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue