aboutsummaryrefslogtreecommitdiffstats
path: root/CommonLibs
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2015-07-30 20:04:18 -0400
committerTom Tsou <tom.tsou@ettus.com>2016-04-20 12:33:41 -0700
commita8cf2086165480597251c2af240e0f44c47097f8 (patch)
tree72a86d413a7609afe155787b27d7da01a8516a55 /CommonLibs
parentf84232d30a247584366b87c91baf9a9f70a5cc49 (diff)
Common: Make sure gLogEarly() log to the same facilities as the normal log.
Diffstat (limited to 'CommonLibs')
-rw-r--r--CommonLibs/Logger.cpp39
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);
}