|
@@ -25,6 +25,7 @@
|
|
|
/// the logging parameters from the configuration database.
|
|
|
|
|
|
#include <algorithm>
|
|
|
+#include <iostream>
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
#include <boost/lexical_cast.hpp>
|
|
@@ -128,5 +129,76 @@ initLogger(const string& root, isc::log::Severity severity, int dbglevel,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// Logger Run-Time Initialization via Environment Variables
|
|
|
+void initLogger() {
|
|
|
+
|
|
|
+ // Root logger name is defined by the environment variable B10_LOGGER_ROOT.
|
|
|
+ // If not present, the name is "b10root".
|
|
|
+ const char* DEFAULT_ROOT = "b10root";
|
|
|
+ const char* root = getenv("B10_LOGGER_ROOT");
|
|
|
+ if (! root) {
|
|
|
+ root = DEFAULT_ROOT;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Set the logging severity. The environment variable is
|
|
|
+ // B10_LOGGER_SEVERITY, and can be one of "DEBUG", "INFO", "WARN", "ERROR"
|
|
|
+ // of "FATAL". Note that the string must be in upper case with no leading
|
|
|
+ // of trailing blanks.
|
|
|
+ isc::log::Severity severity = isc::log::DEFAULT;
|
|
|
+ const char* sev_char = getenv("B10_LOGGER_SEVERITY");
|
|
|
+ if (sev_char) {
|
|
|
+ string sev_string(sev_char);
|
|
|
+ if (sev_string == "DEBUG") {
|
|
|
+ severity = isc::log::DEBUG;
|
|
|
+ } else if (sev_string == "INFO") {
|
|
|
+ severity = isc::log::INFO;
|
|
|
+ } else if (sev_string == "WARN") {
|
|
|
+ severity = isc::log::WARN;
|
|
|
+ } else if (sev_string == "ERROR") {
|
|
|
+ severity = isc::log::ERROR;
|
|
|
+ } else if (sev_string == "FATAL") {
|
|
|
+ severity = isc::log::FATAL;
|
|
|
+ } else {
|
|
|
+ std::cerr << "**ERROR** unrecognised logger severity of '"
|
|
|
+ << sev_string << "' - default severity will be used\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // If the severity is debug, get the debug level (environment variable
|
|
|
+ // B10_LOGGER_DBGLEVEL), which should be in the range 0 to 99.
|
|
|
+ int dbglevel = 0;
|
|
|
+ if (severity == isc::log::DEBUG) {
|
|
|
+ const char* dbg_char = getenv("B10_LOGGER_DBGLEVEL");
|
|
|
+ if (dbg_char) {
|
|
|
+ int level = 0;
|
|
|
+ try {
|
|
|
+ level = boost::lexical_cast<int>(dbg_char);
|
|
|
+ if (level < MIN_DEBUG_LEVEL) {
|
|
|
+ std::cerr << "**ERROR** debug level of " << level
|
|
|
+ << " is invalid - a value of " << MIN_DEBUG_LEVEL
|
|
|
+ << " will be used\n";
|
|
|
+ level = MIN_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";
|
|
|
+ level = MAX_DEBUG_LEVEL;
|
|
|
+ }
|
|
|
+ } catch (...) {
|
|
|
+ // Error, but not fatal to the test
|
|
|
+ std::cerr << "**ERROR** Unable to translate "
|
|
|
+ "B10_LOGGER_DBGLEVEL - a value of 0 will be used\n";
|
|
|
+ }
|
|
|
+ dbglevel = level;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Set the local message file
|
|
|
+ const char* localfile = getenv("B10_LOGGER_LOCALMSG");
|
|
|
+
|
|
|
+ // Initialize logging
|
|
|
+ initLogger(root, severity, dbglevel, localfile);
|
|
|
+}
|
|
|
+
|
|
|
} // namespace log
|
|
|
} // namespace isc
|