|
@@ -12,28 +12,9 @@
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE
|
|
// PERFORMANCE OF THIS SOFTWARE
|
|
|
|
|
|
-/// \brief Temporary Logger Support
|
|
|
|
-///
|
|
|
|
-/// Performs run-time initialization of the logger system. In particular, it
|
|
|
|
-/// is passed information from the command line and:
|
|
|
|
-///
|
|
|
|
-/// a) Sets the severity of the messages being logged (and debug level if
|
|
|
|
-/// appropriate).
|
|
|
|
-/// b) Reads in the local message file is one has been supplied.
|
|
|
|
-///
|
|
|
|
-/// These functions will be replaced once the code has been written to obtain
|
|
|
|
-/// the logging parameters from the configuration database.
|
|
|
|
-
|
|
|
|
-#include <iostream>
|
|
|
|
-#include <algorithm>
|
|
|
|
-#include <iostream>
|
|
|
|
#include <string>
|
|
#include <string>
|
|
-
|
|
|
|
-#include <log/logger_level.h>
|
|
|
|
-#include <log/logger_manager.h>
|
|
|
|
-#include <log/logger_specification.h>
|
|
|
|
#include <log/logger_support.h>
|
|
#include <log/logger_support.h>
|
|
-#include <log/output_option.h>
|
|
+#include <log/logger_manager.h>
|
|
|
|
|
|
using namespace std;
|
|
using namespace std;
|
|
|
|
|
|
@@ -42,80 +23,6 @@ namespace {
|
|
// Flag to hold logging initialization state.
|
|
// Flag to hold logging initialization state.
|
|
bool logging_init_state = false;
|
|
bool logging_init_state = false;
|
|
|
|
|
|
-
|
|
|
|
-// Set logging destination according to the setting of B10_LOGGER_DESTINATION.
|
|
|
|
-// (See header for initLogger() for more details.) This is a no-op if the
|
|
|
|
-// environment variable is not defined.
|
|
|
|
-//
|
|
|
|
-// \param root Name of the root logger
|
|
|
|
-// \param severity Severity level to be assigned to the root logger
|
|
|
|
-// \param dbglevel Debug level
|
|
|
|
-
|
|
|
|
-void
|
|
|
|
-setDestination(const char* root, const isc::log::Severity severity,
|
|
|
|
- const int dbglevel) {
|
|
|
|
-
|
|
|
|
- using namespace isc::log;
|
|
|
|
-
|
|
|
|
- // Constants: not declared static as this is function is expected to be
|
|
|
|
- // called once only
|
|
|
|
- const string DEVNULL = "/dev/null";
|
|
|
|
- const string STDOUT = "stdout";
|
|
|
|
- const string STDERR = "stderr";
|
|
|
|
- const string SYSLOG = "syslog";
|
|
|
|
- const string SYSLOG_COLON = "syslog:";
|
|
|
|
-
|
|
|
|
- // Get the destination. If not specified, assume /dev/null. (The default
|
|
|
|
- // severity for unit tests is DEBUG, which generates a lot of output.
|
|
|
|
- // Routing the logging to /dev/null will suppress that, whilst still
|
|
|
|
- // ensuring that the code paths are tested.)
|
|
|
|
- const char* destination = getenv("B10_LOGGER_DESTINATION");
|
|
|
|
- const string dest((destination == NULL) ? DEVNULL : destination);
|
|
|
|
-
|
|
|
|
- // Prepare the objects to define the logging specification
|
|
|
|
- LoggerSpecification spec(root, severity, dbglevel);
|
|
|
|
- OutputOption option;
|
|
|
|
-
|
|
|
|
- // Set up output option according to destination specification
|
|
|
|
- if (dest == STDOUT) {
|
|
|
|
- option.destination = OutputOption::DEST_CONSOLE;
|
|
|
|
- option.stream = OutputOption::STR_STDOUT;
|
|
|
|
-
|
|
|
|
- } else if (dest == STDERR) {
|
|
|
|
- option.destination = OutputOption::DEST_CONSOLE;
|
|
|
|
- option.stream = OutputOption::STR_STDERR;
|
|
|
|
-
|
|
|
|
- } else if (dest == SYSLOG) {
|
|
|
|
- option.destination = OutputOption::DEST_SYSLOG;
|
|
|
|
- // Use default specified in OutputOption constructor for the
|
|
|
|
- // syslog destination
|
|
|
|
-
|
|
|
|
- } else if (dest.find(SYSLOG_COLON) == 0) {
|
|
|
|
- option.destination = OutputOption::DEST_SYSLOG;
|
|
|
|
- // Must take account of the string actually being "syslog:"
|
|
|
|
- if (dest == SYSLOG_COLON) {
|
|
|
|
- cerr << "**ERROR** value for B10_LOGGER_DESTINATION of " <<
|
|
|
|
- SYSLOG_COLON << " is invalid, " << SYSLOG <<
|
|
|
|
- " will be used instead\n";
|
|
|
|
- // Use default for logging facility
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- // Everything else in the string is the facility name
|
|
|
|
- option.facility = dest.substr(SYSLOG_COLON.size());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- // Not a recognised destination, assume a file.
|
|
|
|
- option.destination = OutputOption::DEST_FILE;
|
|
|
|
- option.filename = dest;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ... and set the destination
|
|
|
|
- spec.addOutputOption(option);
|
|
|
|
- LoggerManager manager;
|
|
|
|
- manager.process(spec);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
} // Anonymous namespace
|
|
} // Anonymous namespace
|
|
|
|
|
|
namespace isc {
|
|
namespace isc {
|
|
@@ -143,63 +50,5 @@ initLogger(const string& root, isc::log::Severity severity, int dbglevel,
|
|
LoggerManager::init(root, severity, dbglevel, file);
|
|
LoggerManager::init(root, severity, dbglevel, file);
|
|
}
|
|
}
|
|
|
|
|
|
-// Logger Run-Time Initialization via Environment Variables
|
|
|
|
-void initLogger(isc::log::Severity severity, int dbglevel) {
|
|
|
|
-
|
|
|
|
- // Root logger name is defined by the environment variable B10_LOGGER_ROOT.
|
|
|
|
- // If not present, the name is "bind10".
|
|
|
|
- const char* DEFAULT_ROOT = "bind10";
|
|
|
|
- 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.
|
|
|
|
- const char* sev_char = getenv("B10_LOGGER_SEVERITY");
|
|
|
|
- if (sev_char) {
|
|
|
|
- severity = isc::log::getSeverity(sev_char);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // If the severity is debug, get the debug level (environment variable
|
|
|
|
- // B10_LOGGER_DBGLEVEL), which should be in the range 0 to 99.
|
|
|
|
- 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) {
|
|
|
|
- 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) {
|
|
|
|
- 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
|
|
|
|
- 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);
|
|
|
|
-
|
|
|
|
- // Now set the destination for logging output
|
|
|
|
- setDestination(root, severity, dbglevel);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
} // namespace log
|
|
} // namespace log
|
|
} // namespace isc
|
|
} // namespace isc
|