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>
17#include <log/message_types.h>
18
19#include <util/strutil.h>
20
21using namespace std;
22
23namespace isc {
24namespace log {
25
26// Initialize underlying logger, but only if logging has been initialized.
27void Logger::initLoggerImpl() {
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
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
48std::string
50 return (LoggerImpl::getVersion());
51}
52
53// Get Name of Logger
54
55std::string
57 return (getLoggerPtr()->getName());
58}
59
60// Set the severity for logging.
61
62void
63Logger::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
78 return (getLoggerPtr()->getEffectiveSeverity());
79}
80
81// Debug level (only relevant if messages of severity DEBUG are being logged).
82
83int
85 return (getLoggerPtr()->getDebugLevel());
86}
87
88// Effective debug level (only relevant if messages of severity DEBUG are being
89// logged).
90
91int
93 return (getLoggerPtr()->getEffectiveDebugLevel());
94}
95
96// Check on the current severity settings
97
98bool
100 return (getLoggerPtr()->isDebugEnabled(dbglevel));
101}
102
103bool
105 return (getLoggerPtr()->isInfoEnabled());
106}
107
108bool
110 return (getLoggerPtr()->isWarnEnabled());
111}
112
113bool
115 return (getLoggerPtr()->isErrorEnabled());
116}
117
118bool
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
132void
133Logger::output(const Severity& severity, const std::string& message) {
134 getLoggerPtr()->outputRaw(severity, message);
135}
136
138Logger::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
149 if (isInfoEnabled()) {
150 return (Formatter(INFO, getLoggerPtr()->lookupMessage(ident),
151 this));
152 } else {
153 return (Formatter());
154 }
155}
156
159 if (isWarnEnabled()) {
160 return (Formatter(WARN, getLoggerPtr()->lookupMessage(ident),
161 this));
162 } else {
163 return (Formatter());
164 }
165}
166
169 if (isErrorEnabled()) {
170 return (Formatter(ERROR, getLoggerPtr()->lookupMessage(ident),
171 this));
172 } else {
173 return (Formatter());
174 }
175}
176
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
189void
191 getLoggerPtr()->setInterprocessSync(sync);
192}
193
194// Comparison (testing only)
195
196bool
198 return (*getLoggerPtr() == *other.getLoggerPtr());
199}
200
201} // namespace log
202} // namespace isc
The log message formatter.
void outputRaw(const Severity &severity, const std::string &message)
Raw output.
Definition: logger_impl.cc:152
virtual void setSeverity(Severity severity, int dbglevel=1)
Set Severity Level for Logger.
Definition: logger_impl.cc:94
void setInterprocessSync(isc::log::interprocess::InterprocessSync *sync)
Replace the interprocess synchronization object.
Definition: logger_impl.cc:140
static std::string getVersion()
Version.
Definition: logger_impl.cc:85
Logger Class.
Definition: log/logger.h:143
Formatter error(const MessageID &ident)
Output Error Message.
Definition: log/logger.cc:168
Formatter info(const MessageID &ident)
Output Informational Message.
Definition: log/logger.cc:148
isc::log::Formatter< Logger > Formatter
The formatter used to replace placeholders.
Definition: log/logger.h:199
Formatter warn(const MessageID &ident)
Output Warning Message.
Definition: log/logger.cc:158
virtual void setSeverity(isc::log::Severity severity, int dbglevel=1)
Set Severity Level for Logger.
Definition: log/logger.cc:63
void setInterprocessSync(isc::log::interprocess::InterprocessSync *sync)
Replace the interprocess synchronization object.
Definition: log/logger.cc:190
Formatter debug(int dbglevel, const MessageID &ident)
Output Debug Message.
Definition: log/logger.cc:138
virtual int getEffectiveDebugLevel()
Get Effective Debug Level for Logger.
Definition: log/logger.cc:92
virtual isc::log::Severity getEffectiveSeverity()
Get Effective Severity Level for Logger.
Definition: log/logger.cc:77
virtual ~Logger()
Destructor.
Definition: log/logger.cc:38
virtual isc::log::Severity getSeverity()
Get Severity Level for Logger.
Definition: log/logger.cc:70
virtual bool isWarnEnabled()
Is WARNING Enabled?
Definition: log/logger.cc:109
virtual bool isFatalEnabled()
Is FATAL Enabled?
Definition: log/logger.cc:119
Formatter fatal(const MessageID &ident)
Output Fatal Message.
Definition: log/logger.cc:178
virtual bool isDebugEnabled(int dbglevel=MIN_DEBUG_LEVEL)
Returns if Debug Message Should Be Output.
Definition: log/logger.cc:99
virtual bool isInfoEnabled()
Is INFO Enabled?
Definition: log/logger.cc:104
bool operator==(Logger &other)
Equality.
Definition: log/logger.cc:197
virtual std::string getName()
Get Name of Logger.
Definition: log/logger.cc:56
virtual bool isErrorEnabled()
Is ERROR Enabled?
Definition: log/logger.cc:114
static std::string getVersion()
Version.
Definition: log/logger.cc:49
virtual int getDebugLevel()
Return DEBUG Level.
Definition: log/logger.cc:84
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Logging initialization functions.
bool isLoggingInitialized()
Is logging initialized?
const char * MessageID
Definition: message_types.h:15
Severity
Severity Levels.
Definition: logger_level.h:23
Defines the logger used by the top-level component of kea-dhcp-ddns.