laforge
/
openbts-osmo
Archived
1
0
Fork 0

Initialize logger right after loading config file.

This avoids printing of log messages to the screen on program startup.
master
Alexander Chemeris 12 years ago committed by Thomas Tsou
parent a5c9b9ecbb
commit 7be28a2263
  1. 16
      public-trunk/CommonLibs/Logger.cpp
  2. 18
      public-trunk/CommonLibs/Logger.h
  3. 6
      public-trunk/apps/OpenBTS.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

@ -103,16 +103,24 @@ std::ostringstream& operator<<(std::ostringstream& os, Log::Level);
std::list<std::string> gGetLoggerAlarms(); ///< Get a copy of the recent alarm list.
/**@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);
//@}
/**@name Global logging file control. */
//@{
void gSetLogFile(FILE*);
bool gSetLogFile(const char*);
/** Class to initialize Logger during static variables initialization. */
class LogInitializer {
public:
LogInitializer(const char *logFile=NULL);
};
//@}

@ -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) {