Rename --debug to --log-level.

Refs #6276
This commit is contained in:
Gunnar Beutner 2014-05-23 18:05:04 +02:00
parent f88f23fa3b
commit 16a2d36bdc
6 changed files with 24 additions and 78 deletions

View File

@ -334,7 +334,7 @@ int Main(void)
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file") ("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
("no-config,z", "start without a configuration file") ("no-config,z", "start without a configuration file")
("validate,C", "exit after validating the configuration") ("validate,C", "exit after validating the configuration")
("debug,x", po::value<std::string>(), "enable debugging with severity level specified") ("log-level,x", po::value<std::string>(), "specify the log level for the console log")
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize)") ("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
#ifndef _WIN32 #ifndef _WIN32
("reload-internal", po::value<int>(), "used internally to implement config reload: do not call manually, send SIGHUP instead") ("reload-internal", po::value<int>(), "used internally to implement config reload: do not call manually, send SIGHUP instead")
@ -428,18 +428,9 @@ int Main(void)
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
if (g_AppParams.count("debug")) { if (g_AppParams.count("log-level")) {
Application::SetDebugging(true); LogSeverity logLevel = Logger::StringToSeverity(g_AppParams["log-level"].as<std::string>());
Logger::SetConsoleLogSeverity(logLevel);
LogSeverity debug_severity;
try {
debug_severity = Logger::StringToSeverity(g_AppParams["debug"].as<std::string>());
} catch (std::exception&) {
//not set, use default
debug_severity = LogDebug;
}
Application::SetDebuggingSeverity(debug_severity);
} }
if (g_AppParams.count("help") || g_AppParams.count("version")) { if (g_AppParams.count("help") || g_AppParams.count("version")) {

View File

@ -50,8 +50,6 @@ bool Application::m_RequestRestart = false;
bool Application::m_RequestReopenLogs = false; bool Application::m_RequestReopenLogs = false;
pid_t Application::m_ReloadProcess = 0; pid_t Application::m_ReloadProcess = 0;
static bool l_Restarting = false; static bool l_Restarting = false;
bool Application::m_Debugging = false;
LogSeverity Application::m_DebuggingSeverity = LogDebug;
int Application::m_ArgC; int Application::m_ArgC;
char **Application::m_ArgV; char **Application::m_ArgV;
double Application::m_StartTime; double Application::m_StartTime;
@ -75,11 +73,6 @@ void Application::OnConfigLoaded(void)
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
#ifdef _WIN32
if (IsDebuggerPresent())
m_Debugging = true;
#endif /* _WIN32 */
ASSERT(m_Instance == NULL); ASSERT(m_Instance == NULL);
m_Instance = this; m_Instance = this;
} }
@ -440,49 +433,6 @@ String Application::GetExePath(const String& argv0)
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
/**
* Sets whether debugging is enabled.
*
* @param debug Whether to enable debugging.
*/
void Application::SetDebugging(bool debug)
{
m_Debugging = debug;
}
/**
* Retrieves the debugging mode of the application.
*
* @returns true if the application is being debugged, false otherwise
*/
bool Application::IsDebugging(void)
{
return m_Debugging;
}
/**
* Sets debugging severity.
*
* @param severity Debug log severity.
*/
void Application::SetDebuggingSeverity(LogSeverity severity)
{
Application::m_DebuggingSeverity = severity;
}
/**
* Retrieves the debugging severity of the application.
*
* @returns severity 'debug' if not set, severity value otherwise.
*/
LogSeverity Application::GetDebuggingSeverity(void)
{
if (!Application::m_DebuggingSeverity)
return LogDebug;
return Application::m_DebuggingSeverity;
}
/** /**
* Display version information. * Display version information.
*/ */

View File

@ -69,9 +69,6 @@ public:
static void RequestRestart(void); static void RequestRestart(void);
static void RequestReopenLogs(void); static void RequestReopenLogs(void);
static void SetDebugging(bool debug);
static bool IsDebugging(void);
static void SetDebuggingSeverity(LogSeverity severity); static void SetDebuggingSeverity(LogSeverity severity);
static LogSeverity GetDebuggingSeverity(void); static LogSeverity GetDebuggingSeverity(void);

View File

@ -36,6 +36,7 @@ INITIALIZE_ONCE(&Logger::StaticInitialize);
std::set<Logger::Ptr> Logger::m_Loggers; std::set<Logger::Ptr> Logger::m_Loggers;
boost::mutex Logger::m_Mutex; boost::mutex Logger::m_Mutex;
bool Logger::m_ConsoleLogEnabled = true; bool Logger::m_ConsoleLogEnabled = true;
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
void Logger::StaticInitialize(void) void Logger::StaticInitialize(void)
{ {
@ -105,14 +106,7 @@ void icinga::Log(LogSeverity severity, const String& facility,
logger->ProcessLogEntry(entry); logger->ProcessLogEntry(entry);
} }
LogSeverity defaultLogLevel; if (Logger::IsConsoleLogEnabled() && entry.Severity >= Logger::GetConsoleLogSeverity()) {
if (Application::IsDebugging())
defaultLogLevel = Application::GetDebuggingSeverity();
else
defaultLogLevel = LogInformation;
if (Logger::IsConsoleLogEnabled() && entry.Severity >= defaultLogLevel) {
static bool tty = StreamLogger::IsTty(std::cout); static bool tty = StreamLogger::IsTty(std::cout);
StreamLogger::ProcessLogEntry(std::cout, tty, entry); StreamLogger::ProcessLogEntry(std::cout, tty, entry);
@ -187,3 +181,12 @@ bool Logger::IsConsoleLogEnabled(void)
return m_ConsoleLogEnabled; return m_ConsoleLogEnabled;
} }
void Logger::SetConsoleLogSeverity(LogSeverity logSeverity)
{
m_ConsoleLogSeverity = logSeverity;
}
LogSeverity Logger::GetConsoleLogSeverity(void)
{
return m_ConsoleLogSeverity;
}

View File

@ -68,6 +68,9 @@ public:
static void DisableConsoleLog(void); static void DisableConsoleLog(void);
static bool IsConsoleLogEnabled(void); static bool IsConsoleLogEnabled(void);
static void SetConsoleLogSeverity(LogSeverity logSeverity);
static LogSeverity GetConsoleLogSeverity(void);
static void StaticInitialize(void); static void StaticInitialize(void);
protected: protected:
@ -78,6 +81,7 @@ private:
static boost::mutex m_Mutex; static boost::mutex m_Mutex;
static std::set<Logger::Ptr> m_Loggers; static std::set<Logger::Ptr> m_Loggers;
static bool m_ConsoleLogEnabled; static bool m_ConsoleLogEnabled;
static LogSeverity m_ConsoleLogSeverity;
friend I2_BASE_API void Log(LogSeverity severity, const String& facility, friend I2_BASE_API void Log(LogSeverity severity, const String& facility,
const String& message); const String& message);

View File

@ -37,10 +37,11 @@ String icinga::JsonSerialize(const Value& value)
char *jsonString; char *jsonString;
if (Application::IsDebugging()) #ifdef _DEBUG
jsonString = cJSON_Print(json); jsonString = cJSON_Print(json);
else #else /* _DEBUG */
jsonString = cJSON_PrintUnformatted(json); jsonString = cJSON_PrintUnformatted(json);
#endif /* _DEBUG */
cJSON_Delete(json); cJSON_Delete(json);