* implement --loglevel option

This commit is contained in:
hagen 2015-12-28 00:00:00 +00:00
parent 2dae5bccb2
commit a0e8fe5848
4 changed files with 24 additions and 5 deletions

View File

@ -110,9 +110,10 @@ namespace i2p
logfile_path.append("\\i2pd.log");
#endif
StartLog (logfile_path);
}
else
} else {
StartLog (""); // write to stdout
}
g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info"));
}
LogPrint(eLogInfo, "Daemon: staring HTTP Server");

13
Log.cpp
View File

@ -55,6 +55,19 @@ void Log::SetLogFile (const std::string& fullFilePath)
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)
{
if (m_LogStream) delete m_LogStream;

10
Log.h
View File

@ -38,9 +38,11 @@ class Log: public i2p::util::MsgQueue<LogMsg>
~Log () { delete m_LogStream; };
void SetLogFile (const std::string& fullFilePath);
void SetLogLevel (const std::string& level);
void SetLogStream (std::ostream * logStream);
std::ostream * GetLogStream () const { return m_LogStream; };
const std::string& GetTimestamp ();
LogLevel GetLogLevel () { return m_MinLevel; };
private:
@ -49,6 +51,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
private:
std::ostream * m_LogStream;
enum LogLevel m_MinLevel;
std::string m_Timestamp;
#if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6) && !defined(__clang__) // gcc 4.6
std::chrono::monotonic_clock::time_point m_LastTimestampUpdate;
@ -108,13 +111,14 @@ void LogPrint (std::stringstream& s, TValue arg, TArgs... args)
template<typename... TArgs>
void LogPrint (LogLevel level, TArgs... args)
{
if (g_Log && level > g_Log->GetLogLevel ())
return;
LogMsg * msg = new LogMsg (g_Log, level);
LogPrint (msg->s, args...);
msg->s << std::endl;
if (g_Log)
if (g_Log) {
g_Log->Put (msg);
else
{
} else {
msg->Process ();
delete msg;
}

View File

@ -6,6 +6,7 @@ i2pd cmdline options
* --httpaddress= - The address 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.
* --loglevel= - Log messages above this level (debug, *info, warn, error)
* --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).
* --v6= - 1 if supports communication through ipv6, off by default