Browse Source

add loglevel none (closing #998)

pull/1009/head
R4SAS 7 years ago
parent
commit
a6fb3b602e
  1. 3
      contrib/i2pd.conf
  2. 9
      libi2pd/Log.cpp
  3. 3
      libi2pd/Log.h

3
contrib/i2pd.conf

@ -23,7 +23,8 @@ @@ -23,7 +23,8 @@
# log = file
## Path to logfile (default - autodetect)
# logfile = /var/log/i2pd.log
## Log messages above this level (debug, *info, warn, error)
## Log messages above this level (debug, *info, warn, error, none)
## If you set it to none, logging will be disabled
# loglevel = info
## Path to storage of i2pd data (RI, keys, peer profiles, ...)

9
libi2pd/Log.cpp

@ -16,10 +16,11 @@ namespace log { @@ -16,10 +16,11 @@ namespace log {
*/
static const char * g_LogLevelStr[eNumLogLevels] =
{
"none", // eLogNone
"error", // eLogError
"warn", // eLogWarn
"info", // eLogInfo
"debug" // eLogDebug
"debug" // eLogDebug
};
/**
@ -46,6 +47,7 @@ namespace log { @@ -46,6 +47,7 @@ namespace log {
static inline int GetSyslogPrio (enum LogLevel l) {
int priority = LOG_DEBUG;
switch (l) {
case eLogNone : priority = LOG_CRIT; break;
case eLogError : priority = LOG_ERR; break;
case eLogWarning : priority = LOG_WARNING; break;
case eLogInfo : priority = LOG_INFO; break;
@ -105,7 +107,8 @@ namespace log { @@ -105,7 +107,8 @@ namespace log {
}
void Log::SetLogLevel (const std::string& level) {
if (level == "error") { m_MinLevel = eLogError; }
if (level == "none") { m_MinLevel = eLogNone; }
else 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; }
@ -181,6 +184,7 @@ namespace log { @@ -181,6 +184,7 @@ namespace log {
void Log::SendTo (const std::string& path)
{
if (m_LogStream) m_LogStream = nullptr; // close previous
if (m_MinLevel == eLogNone) return;
auto flags = std::ofstream::out | std::ofstream::app;
auto os = std::make_shared<std::ofstream> (path, flags);
if (os->is_open ())
@ -202,6 +206,7 @@ namespace log { @@ -202,6 +206,7 @@ namespace log {
#ifndef _WIN32
void Log::SendTo(const char *name, int facility) {
if (m_MinLevel == eLogNone) return;
m_HasColors = false;
m_Destination = eLogSyslog;
m_LogStream = nullptr;

3
libi2pd/Log.h

@ -25,7 +25,8 @@ @@ -25,7 +25,8 @@
enum LogLevel
{
eLogError = 0,
eLogNone = 0,
eLogError,
eLogWarning,
eLogInfo,
eLogDebug,

Loading…
Cancel
Save