Browse Source

* implement --loglevel option

pull/317/head
hagen 9 years ago
parent
commit
a0e8fe5848
  1. 5
      Daemon.cpp
  2. 13
      Log.cpp
  3. 10
      Log.h
  4. 1
      docs/configuration.md

5
Daemon.cpp

@ -110,10 +110,11 @@ namespace i2p @@ -110,10 +110,11 @@ 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");
d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(i2p::util::config::GetArg("-httpaddress", "127.0.0.1"), i2p::util::config::GetArg("-httpport", 7070)));

13
Log.cpp

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

@ -38,9 +38,11 @@ class Log: public i2p::util::MsgQueue<LogMsg> @@ -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> @@ -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) @@ -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;
}

1
docs/configuration.md

@ -6,6 +6,7 @@ i2pd cmdline options @@ -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

Loading…
Cancel
Save