1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE
#include <stdarg.h>
#include <stdio.h>
#include <log/logger.h>
#include <log/logger_impl.h>
#include <log/logger_name.h>
#include <log/logger_support.h>
#include <log/message_dictionary.h>
#include <log/message_types.h>
#include <util/strutil.h>
using namespace std;
namespace isc {
namespace log {
// Initialize underlying logger, but only if logging has been initialized.
void Logger::initLoggerImpl() {
if (isLoggingInitialized()) {
loggerptr_ = new LoggerImpl(name_);
} else {
isc_throw(LoggingNotInitialized, "attempt to access logging function "
"before logging has been initialized");
}
}
// Destructor.
Logger::~Logger() {
delete loggerptr_;
// The next statement is required for the Kea hooks framework, where a
// statically-linked Kea loads and unloads multiple libraries. See the hooks
// documentation for more details.
loggerptr_ = 0;
}
// Get Name of Logger
std::string
Logger::getName() {
return (getLoggerPtr()->getName());
}
// Set the severity for logging.
void
Logger::setSeverity(isc::log::Severity severity, int dbglevel) {
getLoggerPtr()->setSeverity(severity, dbglevel);
}
// Return the severity of the logger.
isc::log::Severity
Logger::getSeverity() {
return (getLoggerPtr()->getSeverity());
}
// Get Effective Severity Level for Logger
isc::log::Severity
Logger::getEffectiveSeverity() {
return (getLoggerPtr()->getEffectiveSeverity());
}
// Debug level (only relevant if messages of severity DEBUG are being logged).
int
Logger::getDebugLevel() {
return (getLoggerPtr()->getDebugLevel());
}
// Effective debug level (only relevant if messages of severity DEBUG are being
// logged).
int
Logger::getEffectiveDebugLevel() {
return (getLoggerPtr()->getEffectiveDebugLevel());
}
// Check on the current severity settings
bool
Logger::isDebugEnabled(int dbglevel) {
return (getLoggerPtr()->isDebugEnabled(dbglevel));
}
bool
Logger::isInfoEnabled() {
return (getLoggerPtr()->isInfoEnabled());
}
bool
Logger::isWarnEnabled() {
return (getLoggerPtr()->isWarnEnabled());
}
bool
Logger::isErrorEnabled() {
return (getLoggerPtr()->isErrorEnabled());
}
bool
Logger::isFatalEnabled() {
return (getLoggerPtr()->isFatalEnabled());
}
// Format a message: looks up the message text in the dictionary and formats
// it, replacing tokens with arguments.
//
// Owing to the use of variable arguments, this must be inline (hence the
// definition of the macro). Also note that it expects that the message buffer
// "message" is declared in the compilation unit.
// Output methods
void
Logger::output(const Severity& severity, const std::string& message) {
getLoggerPtr()->outputRaw(severity, message);
}
Logger::Formatter
Logger::debug(int dbglevel, const isc::log::MessageID& ident) {
if (isDebugEnabled(dbglevel)) {
return (Formatter(DEBUG, getLoggerPtr()->lookupMessage(ident),
this));
} else {
return (Formatter());
}
}
Logger::Formatter
Logger::info(const isc::log::MessageID& ident) {
if (isInfoEnabled()) {
return (Formatter(INFO, getLoggerPtr()->lookupMessage(ident),
this));
} else {
return (Formatter());
}
}
Logger::Formatter
Logger::warn(const isc::log::MessageID& ident) {
if (isWarnEnabled()) {
return (Formatter(WARN, getLoggerPtr()->lookupMessage(ident),
this));
} else {
return (Formatter());
}
}
Logger::Formatter
Logger::error(const isc::log::MessageID& ident) {
if (isErrorEnabled()) {
return (Formatter(ERROR, getLoggerPtr()->lookupMessage(ident),
this));
} else {
return (Formatter());
}
}
Logger::Formatter
Logger::fatal(const isc::log::MessageID& ident) {
if (isFatalEnabled()) {
return (Formatter(FATAL, getLoggerPtr()->lookupMessage(ident),
this));
} else {
return (Formatter());
}
}
// Replace the interprocess synchronization object
void
Logger::setInterprocessSync(isc::log::interprocess::InterprocessSync* sync) {
getLoggerPtr()->setInterprocessSync(sync);
}
// Comparison (testing only)
bool
Logger::operator==(Logger& other) {
return (*getLoggerPtr() == *other.getLoggerPtr());
}
} // namespace log
} // namespace isc
|