Kea  1.5.0
log/logger.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 <stdarg.h>
10 #include <stdio.h>
11 
12 #include <log/logger.h>
13 #include <log/logger_impl.h>
14 #include <log/logger_name.h>
15 #include <log/logger_support.h>
16 #include <log/message_dictionary.h>
17 #include <log/message_types.h>
18 
19 #include <util/strutil.h>
20 
21 using namespace std;
22 
23 namespace isc {
24 namespace log {
25 
26 // Initialize underlying logger, but only if logging has been initialized.
27 void Logger::initLoggerImpl() {
28  if (isLoggingInitialized()) {
29  loggerptr_ = new LoggerImpl(name_);
30  } else {
31  isc_throw(LoggingNotInitialized, "attempt to access logging function "
32  "before logging has been initialized");
33  }
34 }
35 
36 // Destructor.
37 
38 Logger::~Logger() {
39  delete loggerptr_;
40 
41  // The next statement is required for the Kea hooks framework, where a
42  // statically-linked Kea loads and unloads multiple libraries. See the hooks
43  // documentation for more details.
44  loggerptr_ = 0;
45 }
46 
47 // Get Version
48 std::string
49 Logger::getVersion() {
50  return (LoggerImpl::getVersion());
51 }
52 
53 // Get Name of Logger
54 
55 std::string
56 Logger::getName() {
57  return (getLoggerPtr()->getName());
58 }
59 
60 // Set the severity for logging.
61 
62 void
63 Logger::setSeverity(isc::log::Severity severity, int dbglevel) {
64  getLoggerPtr()->setSeverity(severity, dbglevel);
65 }
66 
67 // Return the severity of the logger.
68 
71  return (getLoggerPtr()->getSeverity());
72 }
73 
74 // Get Effective Severity Level for Logger
75 
77 Logger::getEffectiveSeverity() {
78  return (getLoggerPtr()->getEffectiveSeverity());
79 }
80 
81 // Debug level (only relevant if messages of severity DEBUG are being logged).
82 
83 int
84 Logger::getDebugLevel() {
85  return (getLoggerPtr()->getDebugLevel());
86 }
87 
88 // Effective debug level (only relevant if messages of severity DEBUG are being
89 // logged).
90 
91 int
92 Logger::getEffectiveDebugLevel() {
93  return (getLoggerPtr()->getEffectiveDebugLevel());
94 }
95 
96 // Check on the current severity settings
97 
98 bool
99 Logger::isDebugEnabled(int dbglevel) {
100  return (getLoggerPtr()->isDebugEnabled(dbglevel));
101 }
102 
103 bool
104 Logger::isInfoEnabled() {
105  return (getLoggerPtr()->isInfoEnabled());
106 }
107 
108 bool
109 Logger::isWarnEnabled() {
110  return (getLoggerPtr()->isWarnEnabled());
111 }
112 
113 bool
114 Logger::isErrorEnabled() {
115  return (getLoggerPtr()->isErrorEnabled());
116 }
117 
118 bool
119 Logger::isFatalEnabled() {
120  return (getLoggerPtr()->isFatalEnabled());
121 }
122 
123 // Format a message: looks up the message text in the dictionary and formats
124 // it, replacing tokens with arguments.
125 //
126 // Owing to the use of variable arguments, this must be inline (hence the
127 // definition of the macro). Also note that it expects that the message buffer
128 // "message" is declared in the compilation unit.
129 
130 // Output methods
131 
132 void
133 Logger::output(const Severity& severity, const std::string& message) {
134  getLoggerPtr()->outputRaw(severity, message);
135 }
136 
137 Logger::Formatter
138 Logger::debug(int dbglevel, const isc::log::MessageID& ident) {
139  if (isDebugEnabled(dbglevel)) {
140  return (Formatter(DEBUG, getLoggerPtr()->lookupMessage(ident),
141  this));
142  } else {
143  return (Formatter());
144  }
145 }
146 
148 Logger::info(const isc::log::MessageID& ident) {
149  if (isInfoEnabled()) {
150  return (Formatter(INFO, getLoggerPtr()->lookupMessage(ident),
151  this));
152  } else {
153  return (Formatter());
154  }
155 }
156 
158 Logger::warn(const isc::log::MessageID& ident) {
159  if (isWarnEnabled()) {
160  return (Formatter(WARN, getLoggerPtr()->lookupMessage(ident),
161  this));
162  } else {
163  return (Formatter());
164  }
165 }
166 
168 Logger::error(const isc::log::MessageID& ident) {
169  if (isErrorEnabled()) {
170  return (Formatter(ERROR, getLoggerPtr()->lookupMessage(ident),
171  this));
172  } else {
173  return (Formatter());
174  }
175 }
176 
178 Logger::fatal(const isc::log::MessageID& ident) {
179  if (isFatalEnabled()) {
180  return (Formatter(FATAL, getLoggerPtr()->lookupMessage(ident),
181  this));
182  } else {
183  return (Formatter());
184  }
185 }
186 
187 // Replace the interprocess synchronization object
188 
189 void
190 Logger::setInterprocessSync(isc::log::interprocess::InterprocessSync* sync) {
191  getLoggerPtr()->setInterprocessSync(sync);
192 }
193 
194 // Comparison (testing only)
195 
196 bool
198  return (*getLoggerPtr() == *other.getLoggerPtr());
199 }
200 
201 } // namespace log
202 } // namespace isc
Logger Class.
Definition: log/logger.h:143
isc::log::Severity getSeverity(const std::string &sev_str)
Returns the isc::log::Severity value represented by the given string.
Definition: logger_level.cc:20
bool operator==(const Element &a, const Element &b)
Definition: data.cc:211
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Severity
Severity Levels.
Definition: logger_level.h:23
bool isLoggingInitialized()
Is logging initialized?
Defines the logger used by the top-level component of kea-dhcp-ddns.
The log message formatter.
Logging initialization functions.
const Name & name_
Definition: dns/message.cc:693
const char * MessageID
Definition: message_types.h:15