Initialize logger right after loading config file.
This avoids printing of log messages to the screen on program startup.
This commit is contained in:
parent
a5c9b9ecbb
commit
7be28a2263
|
@ -108,15 +108,13 @@ bool gSetLogFile(const char *name)
|
||||||
assert(name);
|
assert(name);
|
||||||
LOG(DEEPDEBUG) << "setting log path to " << name;
|
LOG(DEEPDEBUG) << "setting log path to " << name;
|
||||||
bool retVal = true;
|
bool retVal = true;
|
||||||
gLogLock.lock();
|
|
||||||
FILE* newLoggingFile = fopen(name,"a+");
|
FILE* newLoggingFile = fopen(name,"a+");
|
||||||
if (!newLoggingFile) {
|
if (!newLoggingFile) {
|
||||||
LOG(ERROR) << "cannot open \"" << name << "\" for logging.";
|
LOG(ERROR) << "cannot open \"" << name << "\" for logging.";
|
||||||
retVal = false;
|
retVal = false;
|
||||||
} else {
|
} else {
|
||||||
gLoggingFile = newLoggingFile;
|
gSetLogFile(newLoggingFile);
|
||||||
}
|
}
|
||||||
gLogLock.unlock();
|
|
||||||
LOG(FORCE) << "new log path " << name;
|
LOG(FORCE) << "new log path " << name;
|
||||||
return retVal;
|
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
|
// vim: ts=4 sw=4
|
||||||
|
|
|
@ -103,18 +103,26 @@ std::ostringstream& operator<<(std::ostringstream& os, Log::Level);
|
||||||
std::list<std::string> gGetLoggerAlarms(); ///< Get a copy of the recent alarm list.
|
std::list<std::string> 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. */
|
/**@name Global logging file control. */
|
||||||
//@{
|
//@{
|
||||||
void gSetLogFile(FILE*);
|
void gSetLogFile(FILE*);
|
||||||
bool gSetLogFile(const char*);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,8 @@ using namespace CommandLine;
|
||||||
|
|
||||||
// Load configuration from a file.
|
// Load configuration from a file.
|
||||||
ConfigurationTable gConfig("OpenBTS.config");
|
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
|
// 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;
|
cout << endl << endl << gOpenBTSWelcome << endl;
|
||||||
|
|
||||||
if (gConfig.defines("Log.FileName")) {
|
|
||||||
gSetLogFile(gConfig.getStr("Log.FileName"));
|
|
||||||
}
|
|
||||||
|
|
||||||
startBTS();
|
startBTS();
|
||||||
|
|
||||||
if (strcasecmp(gConfig.getStr("CLI.Type"),"TCP") == 0) {
|
if (strcasecmp(gConfig.getStr("CLI.Type"),"TCP") == 0) {
|
||||||
|
|
Reference in New Issue