|
@@ -29,28 +29,51 @@
|
|
#include <iostream>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <string>
|
|
|
|
|
|
-#include <log/logger.h>
|
|
|
|
|
|
+#include <log/logger_level.h>
|
|
#include <log/logger_manager.h>
|
|
#include <log/logger_manager.h>
|
|
#include <log/logger_support.h>
|
|
#include <log/logger_support.h>
|
|
|
|
|
|
|
|
+using namespace std;
|
|
|
|
+
|
|
|
|
+namespace {
|
|
|
|
+
|
|
|
|
+// Flag to hold logging initialization state. This is held inside a function
|
|
|
|
+// to ensure that it is correctly initialized even when referenced during
|
|
|
|
+// program initialization (thus avoiding the "static initialization fiasco").
|
|
|
|
+bool&
|
|
|
|
+loggingInitializationFlag() {
|
|
|
|
+ static bool init_flag = false;
|
|
|
|
+ return (init_flag);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+} // Anonymous namespace
|
|
|
|
+
|
|
namespace isc {
|
|
namespace isc {
|
|
namespace log {
|
|
namespace log {
|
|
|
|
|
|
-using namespace std;
|
|
|
|
-
|
|
|
|
-// Declare a logger for the logging subsystem. This is a sub-logger of the
|
|
|
|
-// root logger and is used in all functions in this file.
|
|
|
|
-Logger logger("log");
|
|
|
|
|
|
+// Return initialization state.
|
|
|
|
+bool
|
|
|
|
+isLoggingInitialized() {
|
|
|
|
+ return (loggingInitializationFlag());
|
|
|
|
+}
|
|
|
|
|
|
-/// Logger Run-Time Initialization
|
|
|
|
|
|
+// Set initialization state. (Note: as logging can be initialized via a direct
|
|
|
|
+// call to LoggerManager::init(), this function is called from there, not from
|
|
|
|
+// the initialization functions in this file.
|
|
|
|
+void
|
|
|
|
+setLoggingInitialized(bool state) {
|
|
|
|
+ loggingInitializationFlag() = state;
|
|
|
|
+}
|
|
|
|
|
|
|
|
+// Logger Run-Time Initialization. This function is present for historical
|
|
|
|
+// reasons.
|
|
void
|
|
void
|
|
initLogger(const string& root, isc::log::Severity severity, int dbglevel,
|
|
initLogger(const string& root, isc::log::Severity severity, int dbglevel,
|
|
const char* file) {
|
|
const char* file) {
|
|
LoggerManager::init(root, severity, dbglevel, file);
|
|
LoggerManager::init(root, severity, dbglevel, file);
|
|
}
|
|
}
|
|
|
|
|
|
-/// Logger Run-Time Initialization via Environment Variables
|
|
|
|
|
|
+// Logger Run-Time Initialization via Environment Variables
|
|
void initLogger(isc::log::Severity severity, int dbglevel) {
|
|
void initLogger(isc::log::Severity severity, int dbglevel) {
|
|
|
|
|
|
// Root logger name is defined by the environment variable B10_LOGGER_ROOT.
|
|
// Root logger name is defined by the environment variable B10_LOGGER_ROOT.
|
|
@@ -79,20 +102,20 @@ void initLogger(isc::log::Severity severity, int dbglevel) {
|
|
try {
|
|
try {
|
|
level = boost::lexical_cast<int>(dbg_char);
|
|
level = boost::lexical_cast<int>(dbg_char);
|
|
if (level < MIN_DEBUG_LEVEL) {
|
|
if (level < MIN_DEBUG_LEVEL) {
|
|
- std::cerr << "**ERROR** debug level of " << level
|
|
|
|
- << " is invalid - a value of " << MIN_DEBUG_LEVEL
|
|
|
|
- << " will be used\n";
|
|
|
|
|
|
+ cerr << "**ERROR** debug level of " << level
|
|
|
|
+ << " is invalid - a value of " << MIN_DEBUG_LEVEL
|
|
|
|
+ << " will be used\n";
|
|
level = MIN_DEBUG_LEVEL;
|
|
level = MIN_DEBUG_LEVEL;
|
|
} else if (level > MAX_DEBUG_LEVEL) {
|
|
} else if (level > MAX_DEBUG_LEVEL) {
|
|
- std::cerr << "**ERROR** debug level of " << level
|
|
|
|
- << " is invalid - a value of " << MAX_DEBUG_LEVEL
|
|
|
|
- << " will be used\n";
|
|
|
|
|
|
+ cerr << "**ERROR** debug level of " << level
|
|
|
|
+ << " is invalid - a value of " << MAX_DEBUG_LEVEL
|
|
|
|
+ << " will be used\n";
|
|
level = MAX_DEBUG_LEVEL;
|
|
level = MAX_DEBUG_LEVEL;
|
|
}
|
|
}
|
|
} catch (...) {
|
|
} catch (...) {
|
|
// Error, but not fatal to the test
|
|
// Error, but not fatal to the test
|
|
- std::cerr << "**ERROR** Unable to translate "
|
|
|
|
- "B10_LOGGER_DBGLEVEL - a value of 0 will be used\n";
|
|
|
|
|
|
+ cerr << "**ERROR** Unable to translate "
|
|
|
|
+ "B10_LOGGER_DBGLEVEL - a value of 0 will be used\n";
|
|
}
|
|
}
|
|
dbglevel = level;
|
|
dbglevel = level;
|
|
}
|
|
}
|