mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
* implement --loglevel option
This commit is contained in:
parent
2dae5bccb2
commit
a0e8fe5848
@ -110,9 +110,10 @@ namespace i2p
|
|||||||
logfile_path.append("\\i2pd.log");
|
logfile_path.append("\\i2pd.log");
|
||||||
#endif
|
#endif
|
||||||
StartLog (logfile_path);
|
StartLog (logfile_path);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
StartLog (""); // write to stdout
|
StartLog (""); // write to stdout
|
||||||
|
}
|
||||||
|
g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info"));
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrint(eLogInfo, "Daemon: staring HTTP Server");
|
LogPrint(eLogInfo, "Daemon: staring HTTP Server");
|
||||||
|
13
Log.cpp
13
Log.cpp
@ -55,6 +55,19 @@ void Log::SetLogFile (const std::string& fullFilePath)
|
|||||||
delete logFile;
|
delete logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Log::SetLogLevel (const std::string& level)
|
||||||
|
{
|
||||||
|
if (level == "error") { m_MinLevel = eLogError; }
|
||||||
|
else if (level == "warn") { m_MinLevel = eLogWarning; }
|
||||||
|
else if (level == "info") { m_MinLevel = eLogInfo; }
|
||||||
|
else if (level == "debug") { m_MinLevel = eLogDebug; }
|
||||||
|
else {
|
||||||
|
LogPrint(eLogError, "Log: Unknown loglevel: ", level);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogPrint(eLogInfo, "Log: min msg level set to ", level);
|
||||||
|
}
|
||||||
|
|
||||||
void Log::SetLogStream (std::ostream * logStream)
|
void Log::SetLogStream (std::ostream * logStream)
|
||||||
{
|
{
|
||||||
if (m_LogStream) delete m_LogStream;
|
if (m_LogStream) delete m_LogStream;
|
||||||
|
10
Log.h
10
Log.h
@ -38,9 +38,11 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|||||||
~Log () { delete m_LogStream; };
|
~Log () { delete m_LogStream; };
|
||||||
|
|
||||||
void SetLogFile (const std::string& fullFilePath);
|
void SetLogFile (const std::string& fullFilePath);
|
||||||
|
void SetLogLevel (const std::string& level);
|
||||||
void SetLogStream (std::ostream * logStream);
|
void SetLogStream (std::ostream * logStream);
|
||||||
std::ostream * GetLogStream () const { return m_LogStream; };
|
std::ostream * GetLogStream () const { return m_LogStream; };
|
||||||
const std::string& GetTimestamp ();
|
const std::string& GetTimestamp ();
|
||||||
|
LogLevel GetLogLevel () { return m_MinLevel; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -49,6 +51,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::ostream * m_LogStream;
|
std::ostream * m_LogStream;
|
||||||
|
enum LogLevel m_MinLevel;
|
||||||
std::string m_Timestamp;
|
std::string m_Timestamp;
|
||||||
#if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6) && !defined(__clang__) // gcc 4.6
|
#if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6) && !defined(__clang__) // gcc 4.6
|
||||||
std::chrono::monotonic_clock::time_point m_LastTimestampUpdate;
|
std::chrono::monotonic_clock::time_point m_LastTimestampUpdate;
|
||||||
@ -108,13 +111,14 @@ void LogPrint (std::stringstream& s, TValue arg, TArgs... args)
|
|||||||
template<typename... TArgs>
|
template<typename... TArgs>
|
||||||
void LogPrint (LogLevel level, TArgs... args)
|
void LogPrint (LogLevel level, TArgs... args)
|
||||||
{
|
{
|
||||||
|
if (g_Log && level > g_Log->GetLogLevel ())
|
||||||
|
return;
|
||||||
LogMsg * msg = new LogMsg (g_Log, level);
|
LogMsg * msg = new LogMsg (g_Log, level);
|
||||||
LogPrint (msg->s, args...);
|
LogPrint (msg->s, args...);
|
||||||
msg->s << std::endl;
|
msg->s << std::endl;
|
||||||
if (g_Log)
|
if (g_Log) {
|
||||||
g_Log->Put (msg);
|
g_Log->Put (msg);
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
msg->Process ();
|
msg->Process ();
|
||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ i2pd cmdline options
|
|||||||
* --httpaddress= - The address to listen on (HTTP server)
|
* --httpaddress= - The address to listen on (HTTP server)
|
||||||
* --httpport= - The port to listen on (HTTP server)
|
* --httpport= - The port to listen on (HTTP server)
|
||||||
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
|
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
|
||||||
|
* --loglevel= - Log messages above this level (debug, *info, warn, error)
|
||||||
* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no.
|
* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no.
|
||||||
* --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd).
|
* --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd).
|
||||||
* --v6= - 1 if supports communication through ipv6, off by default
|
* --v6= - 1 if supports communication through ipv6, off by default
|
||||||
|
Loading…
Reference in New Issue
Block a user