diff --git a/public-trunk/CommonLibs/Logger.cpp b/public-trunk/CommonLibs/Logger.cpp index ef1b48c..709e39c 100644 --- a/public-trunk/CommonLibs/Logger.cpp +++ b/public-trunk/CommonLibs/Logger.cpp @@ -108,15 +108,13 @@ bool gSetLogFile(const char *name) assert(name); LOG(DEEPDEBUG) << "setting log path to " << name; bool retVal = true; - gLogLock.lock(); FILE* newLoggingFile = fopen(name,"a+"); if (!newLoggingFile) { LOG(ERROR) << "cannot open \"" << name << "\" for logging."; retVal = false; } else { - gLoggingFile = newLoggingFile; + gSetLogFile(newLoggingFile); } - gLogLock.unlock(); LOG(FORCE) << "new log path " << name; return retVal; } @@ -201,7 +199,17 @@ void gLogInit(const char* defaultLevel) } } - +LogInitializer::LogInitializer(const char *logFile) +{ + gLogInit("INFO"); + if (logFile != NULL) { + gSetLogFile(logFile); + } else if (gConfig.defines("Log.FileName")) { + gSetLogFile(gConfig.getStr("Log.FileName")); + } else { + gSetLogFile(stdout); + } +} // vim: ts=4 sw=4 diff --git a/public-trunk/CommonLibs/Logger.h b/public-trunk/CommonLibs/Logger.h index 6c9d2e5..f25a781 100644 --- a/public-trunk/CommonLibs/Logger.h +++ b/public-trunk/CommonLibs/Logger.h @@ -103,18 +103,26 @@ std::ostringstream& operator<<(std::ostringstream& os, Log::Level); std::list gGetLoggerAlarms(); ///< Get a copy of the recent alarm list. -/**@ Global control and initialization of the logging system. */ -//@{ -void gLogInit(const char* defaultLevel = DEFAULT_LOGGING_LEVEL); -Log::Level gLoggingLevel(const char *filename); -//@} - /**@name Global logging file control. */ //@{ void gSetLogFile(FILE*); bool gSetLogFile(const char*); //@} +/**@ Global control and initialization of the logging system. */ +//@{ +void gLogInit(const char* defaultLevel = DEFAULT_LOGGING_LEVEL); +Log::Level gLoggingLevel(const char *filename); + +/** Class to initialize Logger during static variables initialization. */ +class LogInitializer { +public: + + LogInitializer(const char *logFile=NULL); + +}; +//@} + #endif diff --git a/public-trunk/apps/OpenBTS.cpp b/public-trunk/apps/OpenBTS.cpp index 4e8f861..da28ee1 100644 --- a/public-trunk/apps/OpenBTS.cpp +++ b/public-trunk/apps/OpenBTS.cpp @@ -54,6 +54,8 @@ using namespace CommandLine; // Load configuration from a file. ConfigurationTable gConfig("OpenBTS.config"); +// Initialize Logger form the config. +LogInitializer gLogInitializer; // All of the other globals that rely on the global configuration file need to @@ -310,10 +312,6 @@ int main(int argc, char *argv[]) cout << endl << endl << gOpenBTSWelcome << endl; - if (gConfig.defines("Log.FileName")) { - gSetLogFile(gConfig.getStr("Log.FileName")); - } - startBTS(); if (strcasecmp(gConfig.getStr("CLI.Type"),"TCP") == 0) {