Kea 2.5.7
logger_support.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <string>
10#include <log/logger_support.h>
11#include <log/logger_manager.h>
12#include <log/logger_name.h>
13
14using namespace std;
15
16namespace {
17
18// Flag to hold logging initialization state.
19bool logging_init_state = false;
20
21} // Anonymous namespace
22
23namespace isc {
24namespace log {
25
26// Return initialization state.
27bool
29 return (logging_init_state);
30}
31
32// Set initialization state. (Note: as logging can be initialized via a direct
33// call to LoggerManager::init(), this function is called from there, not from
34// the initialization functions in this file.
35void
37 logging_init_state = state;
38}
39
40// Logger Run-Time Initialization.
41
42void
43initLogger(const string& root, isc::log::Severity severity, int dbglevel,
44 const char* file, bool buffer) {
45 LoggerManager::init(root, severity, dbglevel, file, buffer);
46}
47
48// Reset characteristics of the root logger to that set by the environment
49// variables KEA_LOGGER_SEVERITY, KEA_LOGGER_DBGLEVEL and KEA_LOGGER_DESTINATION.
50
51void
53
54 using namespace isc::log;
55
56 // Constants: not declared static as this is function is expected to be
57 // called once only
58 const string DEVNULL = "/dev/null";
59 const string STDOUT = "stdout";
60 const string STDERR = "stderr";
61 const string SYSLOG = "syslog";
62 const string SYSLOG_COLON = "syslog:";
63
64 // Get the destination. If not specified, assume /dev/null. (The default
65 // severity for unit tests is DEBUG, which generates a lot of output.
66 // Routing the logging to /dev/null will suppress that, whilst still
67 // ensuring that the code paths are tested.)
68 const char* destination = getenv("KEA_LOGGER_DESTINATION");
69 const string dest((destination == NULL) ? DEVNULL : destination);
70
71 // Prepare the objects to define the logging specification
76 OutputOption option;
77
78 // Set up output option according to destination specification
79 if (dest == STDOUT) {
82
83 } else if (dest == STDERR) {
86
87 } else if (dest == SYSLOG) {
89 // Use default specified in OutputOption constructor for the
90 // syslog destination
91
92 } else if (dest.find(SYSLOG_COLON) == 0) {
94 // Must take account of the string actually being "syslog:"
95 if (dest == SYSLOG_COLON) {
96 cerr << "**ERROR** value for KEA_LOGGER_DESTINATION of " <<
97 SYSLOG_COLON << " is invalid, " << SYSLOG <<
98 " will be used instead\n";
99 // Use default for logging facility
100
101 } else {
102 // Everything else in the string is the facility name
103 option.facility = dest.substr(SYSLOG_COLON.size());
104 }
105
106 } else {
107 // Not a recognized destination, assume a file.
109 option.filename = dest;
110 }
111
112 // ... and set the destination
113 spec.addOutputOption(option);
114 LoggerManager manager;
115 manager.process(spec);
116}
117
118} // namespace log
119} // namespace isc
static void init(const std::string &root, isc::log::Severity severity=isc::log::INFO, int dbglevel=0, const char *file=NULL, bool buffer=false)
Run-Time Initialization.
void process(T start, T finish)
Process Specifications.
void addOutputOption(const OutputOption &option)
Add output option.
Logging initialization functions.
void setLoggingInitialized(bool state)
Set state of "logging initialized" flag.
const std::string & getRootLoggerName()
Get root logger name.
Definition: logger_name.cc:33
void initLogger(const string &root, isc::log::Severity severity, int dbglevel, const char *file, bool buffer)
Run-time initialization.
bool isLoggingInitialized()
Is logging initialized?
const int MAX_DEBUG_LEVEL
Definition: logger_level.h:36
int keaLoggerDbglevel(int defdbglevel)
Obtains logging debug level from KEA_LOGGER_DBGLEVEL.
void setDefaultLoggingOutput(bool verbose)
Reset root logger characteristics.
Severity
Severity Levels.
Definition: logger_level.h:23
isc::log::Severity keaLoggerSeverity(isc::log::Severity defseverity)
Obtains logging severity from KEA_LOGGER_SEVERITY.
Defines the logger used by the top-level component of kea-lfc.
Destination destination
Members.
Definition: output_option.h:68
std::string facility
syslog facility
Definition: output_option.h:71
Stream stream
stdout/stderr if console output
Definition: output_option.h:69
std::string filename
Filename if file output.
Definition: output_option.h:72