diff options
author | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2015-07-30 20:04:18 -0400 |
---|---|---|
committer | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2015-09-10 19:57:03 -0400 |
commit | 511a662394ff939ae6a8a8623515543199c3c69a (patch) | |
tree | fc5cc8f43e59fbc26689879542df594e6d975b40 | |
parent | 7d2866164b64d596e28f814ab0731d30074f94f4 (diff) |
Common: Make sure gLogEarly() log to the same facilities as the normal log.
-rw-r--r-- | CommonLibs/Logger.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp index cc4bb42..82391cc 100644 --- a/CommonLibs/Logger.cpp +++ b/CommonLibs/Logger.cpp @@ -38,6 +38,14 @@ using namespace std; +// Switches to enable/disable logging targets +// MUST BE DEFINED BEFORE gConfig FOR gLogEarly() TO WORK CORRECTLY +bool gLogToConsole = true; +bool gLogToSyslog = false; +FILE *gLogToFile = NULL; +Mutex gLogToLock; + + // Reference to a global config table, used all over the system. extern ConfigurationTable gConfig; @@ -67,10 +75,6 @@ const char *levelNames[] = { "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG" }; int numLevels = 8; -bool gLogToConsole = true; -bool gLogToSyslog = false; -FILE *gLogToFile = NULL; -Mutex gLogToLock; int levelStringToInt(const string& name) @@ -269,9 +273,32 @@ void gLogInit(const char* name, const char* level, int facility) void gLogEarly(int level, const char *fmt, ...) { va_list args; - + va_start(args, fmt); - vsyslog(level | LOG_USER, fmt, args); + + if (gLogToSyslog) { + va_list args_copy; + va_copy(args_copy, args); + vsyslog(level | LOG_USER, fmt, args_copy); + va_end(args_copy); + } + + if (gLogToConsole) { + va_list args_copy; + va_copy(args_copy, args); + vprintf(fmt, args_copy); + printf("\n"); + va_end(args_copy); + } + + if (gLogToFile) { + va_list args_copy; + va_copy(args_copy, args); + vfprintf(gLogToFile, fmt, args_copy); + fprintf(gLogToFile, "\n"); + va_end(args_copy); + } + va_end(args); } |