/src/logging-log4cxx/src/main/cpp/logger.cpp
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #include <log4cxx/logger.h> |
19 | | #include <log4cxx/spi/loggingevent.h> |
20 | | #include <log4cxx/logmanager.h> |
21 | | #include <log4cxx/appender.h> |
22 | | #include <log4cxx/level.h> |
23 | | #include <log4cxx/hierarchy.h> |
24 | | #include <log4cxx/helpers/stringhelper.h> |
25 | | #include <log4cxx/helpers/transcoder.h> |
26 | | #include <log4cxx/helpers/appenderattachableimpl.h> |
27 | | #include <log4cxx/helpers/exception.h> |
28 | | #if !defined(LOG4CXX) |
29 | | #define LOG4CXX 1 |
30 | | #endif |
31 | | #include <log4cxx/private/log4cxx_private.h> |
32 | | #include <log4cxx/helpers/aprinitializer.h> |
33 | | |
34 | | using namespace LOG4CXX_NS; |
35 | | using namespace LOG4CXX_NS::helpers; |
36 | | using namespace LOG4CXX_NS::spi; |
37 | | |
38 | | struct Logger::LoggerPrivate |
39 | | { |
40 | | LoggerPrivate(const LogString& name1) |
41 | 2 | : name(name1) |
42 | 2 | , repositoryRaw(0) |
43 | 2 | , additive(true) |
44 | 2 | , levelData(Level::getData()) |
45 | 2 | {} |
46 | | |
47 | | /** |
48 | | The name of this logger. |
49 | | */ |
50 | | LogString name; |
51 | | |
52 | | /** |
53 | | The assigned level of this logger. The |
54 | | <code>level</code> variable need not be assigned a value in |
55 | | which case it is inherited form the hierarchy. */ |
56 | | LevelPtr level; |
57 | | |
58 | | /** |
59 | | The parent of this logger. All loggers have at least one |
60 | | ancestor which is the root logger. */ |
61 | | LoggerPtr parent; |
62 | | |
63 | | /** The resourceBundle for localized messages. |
64 | | |
65 | | @see setResourceBundle, getResourceBundle |
66 | | */ |
67 | | helpers::ResourceBundlePtr resourceBundle; |
68 | | |
69 | | |
70 | | // Loggers need to know what Hierarchy they are in |
71 | | spi::LoggerRepository* repositoryRaw; |
72 | | |
73 | | helpers::AppenderAttachableImpl aai; |
74 | | |
75 | | /** Additivity is set to true by default, that is children inherit |
76 | | the appenders of their ancestors by default. If this variable is |
77 | | set to <code>false</code> then the appenders found in the |
78 | | ancestors of this logger are not used. However, the children |
79 | | of this logger will inherit its appenders, unless the children |
80 | | have their additivity flag set to <code>false</code> too. See |
81 | | the user manual for more details. */ |
82 | | bool additive; |
83 | | |
84 | | Level::DataPtr levelData; |
85 | | }; |
86 | | |
87 | | IMPLEMENT_LOG4CXX_OBJECT(Logger) |
88 | | |
89 | | Logger::Logger(const LogString& name1) |
90 | 2 | : m_priv(std::make_unique<LoggerPrivate>(name1)) |
91 | 2 | , m_threshold(0) |
92 | 2 | { |
93 | 2 | } log4cxx::Logger::Logger(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 90 | 1 | : m_priv(std::make_unique<LoggerPrivate>(name1)) | 91 | 1 | , m_threshold(0) | 92 | 1 | { | 93 | 1 | } |
log4cxx::Logger::Logger(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 90 | 1 | : m_priv(std::make_unique<LoggerPrivate>(name1)) | 91 | 1 | , m_threshold(0) | 92 | 1 | { | 93 | 1 | } |
|
94 | | |
95 | | #if LOG4CXX_ABI_VERSION <= 15 |
96 | | Logger::Logger(Pool& p, const LogString& name) |
97 | 0 | : Logger(name) |
98 | 0 | { |
99 | 0 | } Unexecuted instantiation: log4cxx::Logger::Logger(log4cxx::helpers::Pool&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: log4cxx::Logger::Logger(log4cxx::helpers::Pool&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
100 | | #endif |
101 | | |
102 | | Logger::~Logger() |
103 | 2 | { |
104 | 2 | } |
105 | | |
106 | | void Logger::addAppender(const AppenderPtr newAppender) |
107 | 346 | { |
108 | 346 | m_priv->aai.addAppender(newAppender); |
109 | 346 | if (auto rep = getHierarchy()) |
110 | 346 | { |
111 | 346 | rep->fireAddAppenderEvent(this, newAppender.get()); |
112 | 346 | } |
113 | 346 | } |
114 | | |
115 | | bool Logger::replaceAppender(const AppenderPtr& oldAppender, const AppenderPtr& newAppender) |
116 | 0 | { |
117 | 0 | bool result = m_priv->aai.replaceAppender(oldAppender, newAppender); |
118 | 0 | if (result) |
119 | 0 | { |
120 | 0 | if (auto rep = getHierarchy()) |
121 | 0 | rep->fireAddAppenderEvent(this, newAppender.get()); |
122 | 0 | } |
123 | 0 | return result; |
124 | 0 | } |
125 | | |
126 | | void Logger::replaceAppenders( const AppenderList& newList) |
127 | 0 | { |
128 | 0 | m_priv->aai.replaceAppenders(newList); |
129 | |
|
130 | 0 | if (auto rep = getHierarchy()) |
131 | 0 | { |
132 | 0 | for (auto const& item : newList) |
133 | 0 | rep->fireAddAppenderEvent(this, item.get()); |
134 | 0 | } |
135 | 0 | } |
136 | | |
137 | | void Logger::reconfigure( const AppenderList& newList, bool newAdditivity ) |
138 | 0 | { |
139 | 0 | m_priv->additive = newAdditivity; |
140 | |
|
141 | 0 | replaceAppenders(newList); |
142 | 0 | } |
143 | | |
144 | | void Logger::callAppenders(const spi::LoggingEventPtr& event, Pool& p) const |
145 | 3.46k | { |
146 | 3.46k | int writes = 0; |
147 | | |
148 | 3.46k | for (const Logger* logger = this; |
149 | 10.3k | logger != 0; |
150 | 6.92k | logger = logger->m_priv->parent.get()) |
151 | 6.92k | { |
152 | 6.92k | writes += logger->m_priv->aai.appendLoopOnAppenders(event, p); |
153 | | |
154 | 6.92k | if (!logger->m_priv->additive) |
155 | 0 | { |
156 | 0 | break; |
157 | 0 | } |
158 | 6.92k | } |
159 | | |
160 | 3.46k | auto rep = getHierarchy(); |
161 | | |
162 | 3.46k | if (writes == 0 && rep) |
163 | 0 | { |
164 | 0 | rep->emitNoAppenderWarning(this); |
165 | 0 | } |
166 | 3.46k | } |
167 | | |
168 | | void Logger::closeNestedAppenders() |
169 | 692 | { |
170 | 692 | for (auto& item : getAllAppenders()) |
171 | 0 | { |
172 | 0 | item->close(); |
173 | 0 | } |
174 | 692 | } |
175 | | |
176 | | void Logger::addEvent(const LevelPtr& level, helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
177 | 0 | { |
178 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
179 | 0 | return; |
180 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(messageAppender)); |
181 | 0 | Pool p; |
182 | 0 | callAppenders(event, p); |
183 | 0 | } |
184 | | |
185 | | void Logger::addEvent(const LevelPtr& level, std::string&& message, const LocationInfo& location) const |
186 | 3.46k | { |
187 | 3.46k | if (!getHierarchy()) // Has removeHierarchy() been called? |
188 | 0 | return; |
189 | 3.46k | #if LOG4CXX_LOGCHAR_IS_UTF8 |
190 | 3.46k | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(message)); |
191 | | #else |
192 | | LOG4CXX_DECODE_CHAR(msg, message); |
193 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
194 | | #endif |
195 | 3.46k | Pool p; |
196 | 3.46k | callAppenders(event, p); |
197 | 3.46k | } |
198 | | |
199 | | void Logger::addFatalEvent(std::string&& message, const LocationInfo& location) const |
200 | 0 | { |
201 | 0 | addEvent(m_priv->levelData->Fatal, std::move(message), location); |
202 | 0 | } |
203 | | |
204 | | void Logger::addFatalEvent(helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
205 | 0 | { |
206 | 0 | addEvent(m_priv->levelData->Fatal, std::move(messageAppender), location); |
207 | 0 | } |
208 | | |
209 | | void Logger::addErrorEvent(std::string&& message, const LocationInfo& location) const |
210 | 0 | { |
211 | 0 | addEvent(m_priv->levelData->Error, std::move(message), location); |
212 | 0 | } |
213 | | |
214 | | void Logger::addErrorEvent(helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
215 | 0 | { |
216 | 0 | addEvent(m_priv->levelData->Error, std::move(messageAppender), location); |
217 | 0 | } |
218 | | |
219 | | void Logger::addWarnEvent(std::string&& message, const LocationInfo& location) const |
220 | 0 | { |
221 | 0 | addEvent(m_priv->levelData->Warn, std::move(message), location); |
222 | 0 | } |
223 | | |
224 | | void Logger::addWarnEvent(helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
225 | 0 | { |
226 | 0 | addEvent(m_priv->levelData->Warn, std::move(messageAppender), location); |
227 | 0 | } |
228 | | |
229 | | void Logger::addInfoEvent(std::string&& message, const LocationInfo& location) const |
230 | 0 | { |
231 | 0 | addEvent(m_priv->levelData->Info, std::move(message), location); |
232 | 0 | } |
233 | | |
234 | | void Logger::addInfoEvent(helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
235 | 0 | { |
236 | 0 | addEvent(m_priv->levelData->Info, std::move(messageAppender), location); |
237 | 0 | } |
238 | | |
239 | | void Logger::addDebugEvent(std::string&& message, const LocationInfo& location) const |
240 | 3.46k | { |
241 | 3.46k | addEvent(m_priv->levelData->Debug, std::move(message), location); |
242 | 3.46k | } |
243 | | |
244 | | void Logger::addDebugEvent(helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
245 | 0 | { |
246 | 0 | addEvent(m_priv->levelData->Debug, std::move(messageAppender), location); |
247 | 0 | } |
248 | | |
249 | | void Logger::addTraceEvent(std::string&& message, const LocationInfo& location) const |
250 | 0 | { |
251 | 0 | addEvent(m_priv->levelData->Trace, std::move(message), location); |
252 | 0 | } |
253 | | |
254 | | void Logger::addTraceEvent(helpers::AsyncBuffer&& messageAppender, const LocationInfo& location) const |
255 | 0 | { |
256 | 0 | addEvent(m_priv->levelData->Trace, std::move(messageAppender), location); |
257 | 0 | } |
258 | | |
259 | | void Logger::forcedLog(const LevelPtr& level, const std::string& message, |
260 | | const LocationInfo& location) const |
261 | 0 | { |
262 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
263 | 0 | return; |
264 | 0 | #if LOG4CXX_LOGCHAR_IS_UTF8 |
265 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, message, location); |
266 | | #else |
267 | | LOG4CXX_DECODE_CHAR(msg, message); |
268 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
269 | | #endif |
270 | 0 | Pool p; |
271 | 0 | callAppenders(event, p); |
272 | 0 | } |
273 | | |
274 | | void Logger::forcedLog(const LevelPtr& level1, const std::string& message) const |
275 | 0 | { |
276 | 0 | forcedLog(level1, message, LocationInfo::getLocationUnavailable()); |
277 | 0 | } |
278 | | |
279 | | void Logger::addEventLS(const LevelPtr& level, LogString&& message, const LocationInfo& location) const |
280 | 0 | { |
281 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
282 | 0 | return; |
283 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(message)); |
284 | 0 | Pool p; |
285 | 0 | callAppenders(event, p); |
286 | 0 | } |
287 | | |
288 | | void Logger::forcedLogLS(const LevelPtr& level1, const LogString& message, |
289 | | const LocationInfo& location) const |
290 | 0 | { |
291 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
292 | 0 | return; |
293 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, message, location); |
294 | 0 | Pool p; |
295 | 0 | callAppenders(event, p); |
296 | 0 | } |
297 | | |
298 | | |
299 | | bool Logger::getAdditivity() const |
300 | 0 | { |
301 | 0 | return m_priv->additive; |
302 | 0 | } |
303 | | |
304 | | AppenderList Logger::getAllAppenders() const |
305 | 692 | { |
306 | 692 | return m_priv->aai.getAllAppenders(); |
307 | 692 | } |
308 | | |
309 | | AppenderPtr Logger::getAppender(const LogString& name1) const |
310 | 0 | { |
311 | 0 | return m_priv->aai.getAppender(name1); |
312 | 0 | } |
313 | | |
314 | | const LevelPtr& Logger::getEffectiveLevel() const |
315 | 3.46k | { |
316 | 6.92k | for (const Logger* l = this; l != 0; l = l->m_priv->parent.get()) |
317 | 6.92k | { |
318 | 6.92k | if (l->m_priv->level != 0) |
319 | 3.46k | { |
320 | 3.46k | return l->m_priv->level; |
321 | 3.46k | } |
322 | 6.92k | } |
323 | | |
324 | 0 | throw NullPointerException(LOG4CXX_STR("No level specified for logger or ancestors.")); |
325 | | #if LOG4CXX_RETURN_AFTER_THROW |
326 | | return m_priv->level; |
327 | | #endif |
328 | 3.46k | } |
329 | | |
330 | | #if LOG4CXX_ABI_VERSION <= 15 |
331 | | LoggerRepository* Logger::getLoggerRepository() const |
332 | 0 | { |
333 | 0 | return m_priv->repositoryRaw; |
334 | 0 | } |
335 | | #else |
336 | | LoggerRepositoryPtr Logger::getLoggerRepository() |
337 | | { |
338 | | return LogManager::getLoggerRepository(); |
339 | | } |
340 | | #endif |
341 | | |
342 | | LoggerRepository* Logger::getHierarchy() const |
343 | 11.7k | { |
344 | 11.7k | return m_priv->repositoryRaw; |
345 | 11.7k | } |
346 | | |
347 | | ResourceBundlePtr Logger::getResourceBundle() const |
348 | 0 | { |
349 | 0 | for (const Logger* l = this; l != 0; l = l->m_priv->parent.get()) |
350 | 0 | { |
351 | 0 | if (l->m_priv->resourceBundle != 0) |
352 | 0 | { |
353 | 0 | return l->m_priv->resourceBundle; |
354 | 0 | } |
355 | 0 | } |
356 | | |
357 | | // It might be the case that there is no resource bundle |
358 | 0 | return 0; |
359 | 0 | } |
360 | | |
361 | | |
362 | | LogString Logger::getResourceBundleString(const LogString& key) const |
363 | 0 | { |
364 | 0 | ResourceBundlePtr rb = getResourceBundle(); |
365 | | |
366 | | // This is one of the rare cases where we can use logging in order |
367 | | // to report errors from within log4j. |
368 | 0 | if (rb == 0) |
369 | 0 | { |
370 | 0 | return LogString(); |
371 | 0 | } |
372 | 0 | else |
373 | 0 | { |
374 | 0 | try |
375 | 0 | { |
376 | 0 | return rb->getString(key); |
377 | 0 | } |
378 | 0 | catch (MissingResourceException&) |
379 | 0 | { |
380 | 0 | logLS(Level::getError(), LOG4CXX_STR("No resource is associated with key \"") + |
381 | 0 | key + LOG4CXX_STR("\"."), LocationInfo::getLocationUnavailable()); |
382 | |
|
383 | 0 | return LogString(); |
384 | 0 | } |
385 | 0 | } |
386 | 0 | } |
387 | | |
388 | | |
389 | | LoggerPtr Logger::getParent() const |
390 | 0 | { |
391 | 0 | return m_priv->parent; |
392 | 0 | } |
393 | | |
394 | | const LevelPtr& Logger::getLevel() const |
395 | 1 | { |
396 | 1 | return m_priv->level; |
397 | 1 | } |
398 | | |
399 | | bool Logger::isAttached(const AppenderPtr appender) const |
400 | 0 | { |
401 | 0 | return m_priv->aai.isAttached(appender); |
402 | 0 | } |
403 | | |
404 | | bool Logger::isTraceEnabled() const |
405 | 0 | { |
406 | 0 | auto rep = getHierarchy(); |
407 | |
|
408 | 0 | if (!rep || rep->isDisabled(Level::TRACE_INT)) |
409 | 0 | { |
410 | 0 | return false; |
411 | 0 | } |
412 | | |
413 | 0 | return getEffectiveLevel()->toInt() <= Level::TRACE_INT; |
414 | 0 | } |
415 | | |
416 | | bool Logger::isDebugEnabled() const |
417 | 3.46k | { |
418 | 3.46k | auto rep = getHierarchy(); |
419 | | |
420 | 3.46k | if (!rep || rep->isDisabled(Level::DEBUG_INT)) |
421 | 0 | { |
422 | 0 | return false; |
423 | 0 | } |
424 | | |
425 | 3.46k | return getEffectiveLevel()->toInt() <= Level::DEBUG_INT; |
426 | 3.46k | } |
427 | | |
428 | | bool Logger::isEnabledFor(const LevelPtr& level1) const |
429 | 0 | { |
430 | 0 | auto rep = getHierarchy(); |
431 | |
|
432 | 0 | if (!rep || rep->isDisabled(level1->toInt())) |
433 | 0 | { |
434 | 0 | return false; |
435 | 0 | } |
436 | | |
437 | 0 | return level1->isGreaterOrEqual(getEffectiveLevel()); |
438 | 0 | } |
439 | | |
440 | | |
441 | | bool Logger::isInfoEnabled() const |
442 | 0 | { |
443 | 0 | auto rep = getHierarchy(); |
444 | |
|
445 | 0 | if (!rep || rep->isDisabled(Level::INFO_INT)) |
446 | 0 | { |
447 | 0 | return false; |
448 | 0 | } |
449 | | |
450 | 0 | return getEffectiveLevel()->toInt() <= Level::INFO_INT; |
451 | 0 | } |
452 | | |
453 | | bool Logger::isErrorEnabled() const |
454 | 0 | { |
455 | 0 | auto rep = getHierarchy(); |
456 | |
|
457 | 0 | if (!rep || rep->isDisabled(Level::ERROR_INT)) |
458 | 0 | { |
459 | 0 | return false; |
460 | 0 | } |
461 | | |
462 | 0 | return getEffectiveLevel()->toInt() <= Level::ERROR_INT; |
463 | 0 | } |
464 | | |
465 | | bool Logger::isWarnEnabled() const |
466 | 0 | { |
467 | 0 | auto rep = getHierarchy(); |
468 | |
|
469 | 0 | if (!rep || rep->isDisabled(Level::WARN_INT)) |
470 | 0 | { |
471 | 0 | return false; |
472 | 0 | } |
473 | | |
474 | 0 | return getEffectiveLevel()->toInt() <= Level::WARN_INT; |
475 | 0 | } |
476 | | |
477 | | bool Logger::isFatalEnabled() const |
478 | 0 | { |
479 | 0 | auto rep = getHierarchy(); |
480 | |
|
481 | 0 | if (!rep || rep->isDisabled(Level::FATAL_INT)) |
482 | 0 | { |
483 | 0 | return false; |
484 | 0 | } |
485 | | |
486 | 0 | return getEffectiveLevel()->toInt() <= Level::FATAL_INT; |
487 | 0 | } |
488 | | |
489 | | /*void Logger::l7dlog(const LevelPtr& level, const String& key, |
490 | | const char* file, int line) |
491 | | { |
492 | | auto rep = getHierarchy(); |
493 | | |
494 | | if (!rep || rep->isDisabled(level->level)) |
495 | | { |
496 | | return; |
497 | | } |
498 | | |
499 | | if (level->isGreaterOrEqual(getEffectiveLevel())) |
500 | | { |
501 | | String msg = getResourceBundleString(key); |
502 | | |
503 | | // if message corresponding to 'key' could not be found in the |
504 | | // resource bundle, then default to 'key'. |
505 | | if (msg.empty()) |
506 | | { |
507 | | msg = key; |
508 | | } |
509 | | |
510 | | forcedLog(FQCN, level, msg, file, line); |
511 | | } |
512 | | }*/ |
513 | | |
514 | | |
515 | | |
516 | | void Logger::l7dlog(const LevelPtr& level1, const LogString& key, |
517 | | const LocationInfo& location, const std::vector<LogString>& params) const |
518 | 0 | { |
519 | 0 | auto rep = getHierarchy(); |
520 | |
|
521 | 0 | if (!rep || rep->isDisabled(level1->toInt())) |
522 | 0 | { |
523 | 0 | return; |
524 | 0 | } |
525 | | |
526 | 0 | if (level1->isGreaterOrEqual(getEffectiveLevel())) |
527 | 0 | { |
528 | 0 | LogString pattern = getResourceBundleString(key); |
529 | 0 | LogString msg; |
530 | |
|
531 | 0 | if (pattern.empty()) |
532 | 0 | { |
533 | 0 | msg = key; |
534 | 0 | } |
535 | 0 | else |
536 | 0 | { |
537 | 0 | msg = StringHelper::format(pattern, params); |
538 | 0 | } |
539 | |
|
540 | 0 | addEventLS(level1, std::move(msg), location); |
541 | 0 | } |
542 | 0 | } |
543 | | |
544 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
545 | | const LocationInfo& location) const |
546 | 0 | { |
547 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
548 | |
|
549 | 0 | std::vector<LogString> values(0); |
550 | 0 | l7dlog(level1, lkey, location, values); |
551 | 0 | } |
552 | | |
553 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
554 | | const LocationInfo& location, const std::string& val1) const |
555 | 0 | { |
556 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
557 | 0 | LOG4CXX_DECODE_CHAR(lval1, val1); |
558 | |
|
559 | 0 | std::vector<LogString> values(1); |
560 | 0 | values[0] = lval1; |
561 | 0 | l7dlog(level1, lkey, location, values); |
562 | 0 | } |
563 | | |
564 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
565 | | const LocationInfo& location, |
566 | | const std::string& val1, const std::string& val2) const |
567 | 0 | { |
568 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
569 | 0 | LOG4CXX_DECODE_CHAR(lval1, val1); |
570 | 0 | LOG4CXX_DECODE_CHAR(lval2, val2); |
571 | |
|
572 | 0 | std::vector<LogString> values(2); |
573 | 0 | values[0] = lval1; |
574 | 0 | values[1] = lval2; |
575 | 0 | l7dlog(level1, lkey, location, values); |
576 | 0 | } |
577 | | |
578 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
579 | | const LocationInfo& location, |
580 | | const std::string& val1, const std::string& val2, const std::string& val3) const |
581 | 0 | { |
582 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
583 | 0 | LOG4CXX_DECODE_CHAR(lval1, val1); |
584 | 0 | LOG4CXX_DECODE_CHAR(lval2, val2); |
585 | 0 | LOG4CXX_DECODE_CHAR(lval3, val3); |
586 | |
|
587 | 0 | std::vector<LogString> values(3); |
588 | 0 | values[0] = lval1; |
589 | 0 | values[1] = lval2; |
590 | 0 | values[2] = lval3; |
591 | 0 | l7dlog(level1, lkey, location, values); |
592 | 0 | } |
593 | | |
594 | | void Logger::removeAllAppenders() |
595 | 694 | { |
596 | 694 | AppenderList currentAppenders = m_priv->aai.getAllAppenders(); |
597 | 694 | m_priv->aai.removeAllAppenders(); |
598 | | |
599 | 694 | auto rep = getHierarchy(); |
600 | 694 | if(rep){ |
601 | 692 | for(AppenderPtr appender : currentAppenders){ |
602 | 0 | rep->fireRemoveAppenderEvent(this, appender.get()); |
603 | 0 | } |
604 | 692 | } |
605 | 694 | } |
606 | | |
607 | | void Logger::removeAppender(const AppenderPtr appender) |
608 | 346 | { |
609 | 346 | m_priv->aai.removeAppender(appender); |
610 | 346 | if (auto rep = getHierarchy()) |
611 | 346 | { |
612 | 346 | rep->fireRemoveAppenderEvent(this, appender.get()); |
613 | 346 | } |
614 | 346 | } |
615 | | |
616 | | void Logger::removeAppender(const LogString& name1) |
617 | 0 | { |
618 | 0 | AppenderPtr appender = m_priv->aai.getAppender(name1); |
619 | 0 | if(appender){ |
620 | 0 | removeAppender(appender); |
621 | 0 | } |
622 | 0 | } |
623 | | |
624 | | void Logger::removeHierarchy() |
625 | 2 | { |
626 | 2 | m_priv->repositoryRaw = 0; |
627 | 2 | } |
628 | | |
629 | | void Logger::setAdditivity(bool additive1) |
630 | 0 | { |
631 | 0 | m_priv->additive = additive1; |
632 | 0 | } |
633 | | |
634 | | void Logger::setHierarchy(spi::LoggerRepository* repository1) |
635 | 2 | { |
636 | 2 | m_priv->repositoryRaw = repository1; |
637 | 2 | } |
638 | | |
639 | | void Logger::setParent(LoggerPtr parentLogger) |
640 | 1 | { |
641 | 1 | m_priv->parent = parentLogger; |
642 | 1 | updateThreshold(); |
643 | 1 | } |
644 | | |
645 | | void Logger::setLevel(const LevelPtr level1) |
646 | 1 | { |
647 | 1 | if (m_priv->level != level1) |
648 | 1 | { |
649 | 1 | m_priv->level = level1; |
650 | 1 | updateThreshold(); |
651 | 1 | if (auto rep = dynamic_cast<Hierarchy*>(getHierarchy())) |
652 | 0 | rep->updateChildren(this); |
653 | 1 | } |
654 | 1 | } |
655 | | |
656 | | void Logger::updateThreshold() |
657 | 2 | { |
658 | 2 | m_threshold = getEffectiveLevel()->toInt(); |
659 | 2 | } |
660 | | |
661 | | const LogString& Logger::getName() const |
662 | 1 | { |
663 | 1 | return m_priv->name; |
664 | 1 | } |
665 | | |
666 | | LoggerPtr Logger::getLogger(const std::string& name) |
667 | 0 | { |
668 | 0 | return LogManager::getLogger(name); |
669 | 0 | } |
670 | | |
671 | | |
672 | | LoggerPtr Logger::getLogger(const char* const name) |
673 | 0 | { |
674 | 0 | return LogManager::getLogger(name); |
675 | 0 | } |
676 | | |
677 | | void Logger::setResourceBundle(const helpers::ResourceBundlePtr& bundle) |
678 | 0 | { |
679 | 0 | m_priv->resourceBundle = bundle; |
680 | 0 | } |
681 | | |
682 | | LoggerPtr Logger::getRootLogger() |
683 | 0 | { |
684 | 0 | return LogManager::getRootLogger(); |
685 | 0 | } |
686 | | |
687 | | LoggerPtr Logger::getLoggerLS(const LogString& name, |
688 | | const spi::LoggerFactoryPtr& factory) |
689 | 0 | { |
690 | 0 | return LogManager::getLoggerLS(name, factory); |
691 | 0 | } |
692 | | |
693 | | void Logger::getName(std::string& rv) const |
694 | 0 | { |
695 | 0 | Transcoder::encode(m_priv->name, rv); |
696 | 0 | } |
697 | | |
698 | | |
699 | | void Logger::trace(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
700 | 0 | { |
701 | 0 | if (isTraceEnabled()) |
702 | 0 | { |
703 | 0 | forcedLog(m_priv->levelData->Trace, msg, location); |
704 | 0 | } |
705 | 0 | } |
706 | | |
707 | | |
708 | | void Logger::trace(const std::string& msg) const |
709 | 0 | { |
710 | 0 | if (isTraceEnabled()) |
711 | 0 | { |
712 | 0 | forcedLog(m_priv->levelData->Trace, msg); |
713 | 0 | } |
714 | 0 | } |
715 | | |
716 | | void Logger::debug(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
717 | 0 | { |
718 | 0 | if (isDebugEnabled()) |
719 | 0 | { |
720 | 0 | forcedLog(m_priv->levelData->Debug, msg, location); |
721 | 0 | } |
722 | 0 | } |
723 | | |
724 | | void Logger::debug(const std::string& msg) const |
725 | 0 | { |
726 | 0 | if (isDebugEnabled()) |
727 | 0 | { |
728 | 0 | forcedLog(m_priv->levelData->Debug, msg); |
729 | 0 | } |
730 | 0 | } |
731 | | |
732 | | |
733 | | void Logger::error(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
734 | 0 | { |
735 | 0 | if (isErrorEnabled()) |
736 | 0 | { |
737 | 0 | forcedLog(m_priv->levelData->Error, msg, location); |
738 | 0 | } |
739 | 0 | } |
740 | | |
741 | | |
742 | | void Logger::error(const std::string& msg) const |
743 | 0 | { |
744 | 0 | if (isErrorEnabled()) |
745 | 0 | { |
746 | 0 | forcedLog(m_priv->levelData->Error, msg); |
747 | 0 | } |
748 | 0 | } |
749 | | |
750 | | void Logger::fatal(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
751 | 0 | { |
752 | 0 | if (isFatalEnabled()) |
753 | 0 | { |
754 | 0 | forcedLog(m_priv->levelData->Fatal, msg, location); |
755 | 0 | } |
756 | 0 | } |
757 | | |
758 | | void Logger::fatal(const std::string& msg) const |
759 | 0 | { |
760 | 0 | if (isFatalEnabled()) |
761 | 0 | { |
762 | 0 | forcedLog(m_priv->levelData->Fatal, msg); |
763 | 0 | } |
764 | 0 | } |
765 | | |
766 | | void Logger::info(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
767 | 0 | { |
768 | 0 | if (isInfoEnabled()) |
769 | 0 | { |
770 | 0 | forcedLog(m_priv->levelData->Info, msg, location); |
771 | 0 | } |
772 | 0 | } |
773 | | |
774 | | void Logger::info(const std::string& msg) const |
775 | 0 | { |
776 | 0 | if (isInfoEnabled()) |
777 | 0 | { |
778 | 0 | forcedLog(m_priv->levelData->Info, msg); |
779 | 0 | } |
780 | 0 | } |
781 | | |
782 | | void Logger::log(const LevelPtr& level1, const std::string& message, |
783 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
784 | 0 | { |
785 | 0 | if (isEnabledFor(level1)) |
786 | 0 | { |
787 | 0 | forcedLog(level1, message, location); |
788 | 0 | } |
789 | 0 | } |
790 | | |
791 | | void Logger::log(const LevelPtr& level1, const std::string& message) const |
792 | 0 | { |
793 | 0 | if (isEnabledFor(level1)) |
794 | 0 | { |
795 | 0 | forcedLog(level1, message); |
796 | 0 | } |
797 | 0 | } |
798 | | |
799 | | void Logger::logLS(const LevelPtr& level1, const LogString& message, |
800 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
801 | 0 | { |
802 | 0 | if (isEnabledFor(level1)) |
803 | 0 | { |
804 | 0 | forcedLogLS(level1, message, location); |
805 | 0 | } |
806 | 0 | } |
807 | | |
808 | | void Logger::warn(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
809 | 0 | { |
810 | 0 | if (isWarnEnabled()) |
811 | 0 | { |
812 | 0 | forcedLog(m_priv->levelData->Warn, msg, location); |
813 | 0 | } |
814 | 0 | } |
815 | | |
816 | | void Logger::warn(const std::string& msg) const |
817 | 0 | { |
818 | 0 | if (isWarnEnabled()) |
819 | 0 | { |
820 | 0 | forcedLog(m_priv->levelData->Warn, msg); |
821 | 0 | } |
822 | 0 | } |
823 | | |
824 | | LoggerPtr Logger::getLoggerLS(const LogString& name) |
825 | 0 | { |
826 | 0 | return LogManager::getLoggerLS(name); |
827 | 0 | } |
828 | | |
829 | | |
830 | | |
831 | | |
832 | | #if LOG4CXX_WCHAR_T_API |
833 | | void Logger::addEvent(const LevelPtr& level, std::wstring&& message, const LocationInfo& location) const |
834 | 0 | { |
835 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
836 | 0 | return; |
837 | | #if LOG4CXX_LOGCHAR_IS_WCHAR |
838 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(message)); |
839 | | #else |
840 | 0 | LOG4CXX_DECODE_WCHAR(msg, message); |
841 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
842 | 0 | #endif |
843 | 0 | Pool p; |
844 | 0 | callAppenders(event, p); |
845 | 0 | } |
846 | | |
847 | | void Logger::addFatalEvent(std::wstring&& message, const LocationInfo& location) const |
848 | 0 | { |
849 | 0 | addEvent(m_priv->levelData->Fatal, std::move(message), location); |
850 | 0 | } |
851 | | |
852 | | void Logger::addErrorEvent(std::wstring&& message, const LocationInfo& location) const |
853 | 0 | { |
854 | 0 | addEvent(m_priv->levelData->Error, std::move(message), location); |
855 | 0 | } |
856 | | |
857 | | void Logger::addWarnEvent(std::wstring&& message, const LocationInfo& location) const |
858 | 0 | { |
859 | 0 | addEvent(m_priv->levelData->Warn, std::move(message), location); |
860 | 0 | } |
861 | | |
862 | | void Logger::addInfoEvent(std::wstring&& message, const LocationInfo& location) const |
863 | 0 | { |
864 | 0 | addEvent(m_priv->levelData->Info, std::move(message), location); |
865 | 0 | } |
866 | | |
867 | | void Logger::addDebugEvent(std::wstring&& message, const LocationInfo& location) const |
868 | 0 | { |
869 | 0 | addEvent(m_priv->levelData->Debug, std::move(message), location); |
870 | 0 | } |
871 | | |
872 | | void Logger::addTraceEvent(std::wstring&& message, const LocationInfo& location) const |
873 | 0 | { |
874 | 0 | addEvent(m_priv->levelData->Trace, std::move(message), location); |
875 | 0 | } |
876 | | |
877 | | void Logger::forcedLog(const LevelPtr& level, const std::wstring& message, |
878 | | const LocationInfo& location) const |
879 | 0 | { |
880 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
881 | 0 | return; |
882 | | #if LOG4CXX_LOGCHAR_IS_WCHAR |
883 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, message, location); |
884 | | #else |
885 | 0 | LOG4CXX_DECODE_WCHAR(msg, message); |
886 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
887 | 0 | #endif |
888 | 0 | Pool p; |
889 | 0 | callAppenders(event, p); |
890 | 0 | } |
891 | | |
892 | | void Logger::forcedLog(const LevelPtr& level1, const std::wstring& message) const |
893 | 0 | { |
894 | 0 | forcedLog(level1, message, LocationInfo::getLocationUnavailable()); |
895 | 0 | } |
896 | | |
897 | | void Logger::getName(std::wstring& rv) const |
898 | 0 | { |
899 | 0 | Transcoder::encode(m_priv->name, rv); |
900 | 0 | } |
901 | | |
902 | | LoggerPtr Logger::getLogger(const std::wstring& name) |
903 | 0 | { |
904 | 0 | return LogManager::getLogger(name); |
905 | 0 | } |
906 | | |
907 | | LoggerPtr Logger::getLogger(const wchar_t* const name) |
908 | 0 | { |
909 | 0 | return LogManager::getLogger(name); |
910 | 0 | } |
911 | | |
912 | | void Logger::trace(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
913 | 0 | { |
914 | 0 | if (isTraceEnabled()) |
915 | 0 | { |
916 | 0 | forcedLog(m_priv->levelData->Trace, msg, location); |
917 | 0 | } |
918 | 0 | } |
919 | | |
920 | | |
921 | | void Logger::trace(const std::wstring& msg) const |
922 | 0 | { |
923 | 0 | if (isTraceEnabled()) |
924 | 0 | { |
925 | 0 | forcedLog(m_priv->levelData->Trace, msg); |
926 | 0 | } |
927 | 0 | } |
928 | | |
929 | | void Logger::debug(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
930 | 0 | { |
931 | 0 | if (isDebugEnabled()) |
932 | 0 | { |
933 | 0 | forcedLog(m_priv->levelData->Debug, msg, location); |
934 | 0 | } |
935 | 0 | } |
936 | | |
937 | | void Logger::debug(const std::wstring& msg) const |
938 | 0 | { |
939 | 0 | if (isDebugEnabled()) |
940 | 0 | { |
941 | 0 | forcedLog(m_priv->levelData->Debug, msg); |
942 | 0 | } |
943 | 0 | } |
944 | | |
945 | | void Logger::error(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
946 | 0 | { |
947 | 0 | if (isErrorEnabled()) |
948 | 0 | { |
949 | 0 | forcedLog(m_priv->levelData->Error, msg, location); |
950 | 0 | } |
951 | 0 | } |
952 | | |
953 | | void Logger::error(const std::wstring& msg) const |
954 | 0 | { |
955 | 0 | if (isErrorEnabled()) |
956 | 0 | { |
957 | 0 | forcedLog(m_priv->levelData->Error, msg); |
958 | 0 | } |
959 | 0 | } |
960 | | |
961 | | void Logger::fatal(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
962 | 0 | { |
963 | 0 | if (isFatalEnabled()) |
964 | 0 | { |
965 | 0 | forcedLog(m_priv->levelData->Fatal, msg, location); |
966 | 0 | } |
967 | 0 | } |
968 | | |
969 | | void Logger::fatal(const std::wstring& msg) const |
970 | 0 | { |
971 | 0 | if (isFatalEnabled()) |
972 | 0 | { |
973 | 0 | forcedLog(m_priv->levelData->Fatal, msg); |
974 | 0 | } |
975 | 0 | } |
976 | | |
977 | | void Logger::info(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
978 | 0 | { |
979 | 0 | if (isInfoEnabled()) |
980 | 0 | { |
981 | 0 | forcedLog(m_priv->levelData->Info, msg, location); |
982 | 0 | } |
983 | 0 | } |
984 | | |
985 | | void Logger::info(const std::wstring& msg) const |
986 | 0 | { |
987 | 0 | if (isInfoEnabled()) |
988 | 0 | { |
989 | 0 | forcedLog(m_priv->levelData->Info, msg); |
990 | 0 | } |
991 | 0 | } |
992 | | |
993 | | void Logger::log(const LevelPtr& level1, const std::wstring& message, |
994 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
995 | 0 | { |
996 | 0 | if (isEnabledFor(level1)) |
997 | 0 | { |
998 | 0 | forcedLog(level1, message, location); |
999 | 0 | } |
1000 | 0 | } |
1001 | | |
1002 | | void Logger::log(const LevelPtr& level1, const std::wstring& message) const |
1003 | 0 | { |
1004 | 0 | if (isEnabledFor(level1)) |
1005 | 0 | { |
1006 | 0 | forcedLog(level1, message); |
1007 | 0 | } |
1008 | 0 | } |
1009 | | |
1010 | | void Logger::warn(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1011 | 0 | { |
1012 | 0 | if (isWarnEnabled()) |
1013 | 0 | { |
1014 | 0 | forcedLog(m_priv->levelData->Warn, msg, location); |
1015 | 0 | } |
1016 | 0 | } |
1017 | | |
1018 | | void Logger::warn(const std::wstring& msg) const |
1019 | 0 | { |
1020 | 0 | if (isWarnEnabled()) |
1021 | 0 | { |
1022 | 0 | forcedLog(m_priv->levelData->Warn, msg); |
1023 | 0 | } |
1024 | 0 | } |
1025 | | |
1026 | | #endif |
1027 | | |
1028 | | |
1029 | | #if LOG4CXX_UNICHAR_API |
1030 | | void Logger::addEvent(const LevelPtr& level1, std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1031 | | { |
1032 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1033 | | return; |
1034 | | LOG4CXX_DECODE_UNICHAR(msg, message); |
1035 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg)); |
1036 | | Pool p; |
1037 | | callAppenders(event, p); |
1038 | | } |
1039 | | |
1040 | | void Logger::addFatalEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1041 | | { |
1042 | | addEvent(m_priv->levelData->Fatal, std::move(message), location); |
1043 | | } |
1044 | | |
1045 | | void Logger::addErrorEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1046 | | { |
1047 | | addEvent(m_priv->levelData->Error, std::move(message), location); |
1048 | | } |
1049 | | |
1050 | | void Logger::addWarnEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1051 | | { |
1052 | | addEvent(m_priv->levelData->Warn, std::move(message), location); |
1053 | | } |
1054 | | |
1055 | | void Logger::addInfoEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1056 | | { |
1057 | | addEvent(m_priv->levelData->Info, std::move(message), location); |
1058 | | } |
1059 | | |
1060 | | void Logger::addDebugEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1061 | | { |
1062 | | addEvent(m_priv->levelData->Debug, std::move(message), location); |
1063 | | } |
1064 | | |
1065 | | void Logger::addTraceEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1066 | | { |
1067 | | addEvent(m_priv->levelData->Trace, std::move(message), location); |
1068 | | } |
1069 | | |
1070 | | void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message, |
1071 | | const LocationInfo& location) const |
1072 | | { |
1073 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1074 | | return; |
1075 | | LOG4CXX_DECODE_UNICHAR(msg, message); |
1076 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg)); |
1077 | | Pool p; |
1078 | | callAppenders(event, p); |
1079 | | } |
1080 | | |
1081 | | void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message) const |
1082 | | { |
1083 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1084 | | return; |
1085 | | LOG4CXX_DECODE_UNICHAR(msg, message); |
1086 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, msg, |
1087 | | LocationInfo::getLocationUnavailable()); |
1088 | | Pool p; |
1089 | | callAppenders(event, p); |
1090 | | } |
1091 | | |
1092 | | void Logger::getName(std::basic_string<UniChar>& rv) const |
1093 | | { |
1094 | | Transcoder::encode(m_priv->name, rv); |
1095 | | } |
1096 | | |
1097 | | LoggerPtr Logger::getLogger(const std::basic_string<UniChar>& name) |
1098 | | { |
1099 | | return LogManager::getLogger(name); |
1100 | | } |
1101 | | |
1102 | | void Logger::trace(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1103 | | { |
1104 | | if (isTraceEnabled()) |
1105 | | { |
1106 | | forcedLog(m_priv->levelData->Trace, msg, location); |
1107 | | } |
1108 | | } |
1109 | | |
1110 | | |
1111 | | void Logger::trace(const std::basic_string<UniChar>& msg) const |
1112 | | { |
1113 | | if (isTraceEnabled()) |
1114 | | { |
1115 | | forcedLog(m_priv->levelData->Trace, msg); |
1116 | | } |
1117 | | } |
1118 | | |
1119 | | void Logger::debug(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1120 | | { |
1121 | | if (isDebugEnabled()) |
1122 | | { |
1123 | | forcedLog(m_priv->levelData->Debug, msg, location); |
1124 | | } |
1125 | | } |
1126 | | |
1127 | | void Logger::debug(const std::basic_string<UniChar>& msg) const |
1128 | | { |
1129 | | if (isDebugEnabled()) |
1130 | | { |
1131 | | forcedLog(m_priv->levelData->Debug, msg); |
1132 | | } |
1133 | | } |
1134 | | |
1135 | | void Logger::error(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1136 | | { |
1137 | | if (isErrorEnabled()) |
1138 | | { |
1139 | | forcedLog(m_priv->levelData->Error, msg, location); |
1140 | | } |
1141 | | } |
1142 | | |
1143 | | void Logger::error(const std::basic_string<UniChar>& msg) const |
1144 | | { |
1145 | | if (isErrorEnabled()) |
1146 | | { |
1147 | | forcedLog(m_priv->levelData->Error, msg); |
1148 | | } |
1149 | | } |
1150 | | |
1151 | | void Logger::fatal(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1152 | | { |
1153 | | if (isFatalEnabled()) |
1154 | | { |
1155 | | forcedLog(m_priv->levelData->Fatal, msg, location); |
1156 | | } |
1157 | | } |
1158 | | |
1159 | | void Logger::fatal(const std::basic_string<UniChar>& msg) const |
1160 | | { |
1161 | | if (isFatalEnabled()) |
1162 | | { |
1163 | | forcedLog(m_priv->levelData->Fatal, msg); |
1164 | | } |
1165 | | } |
1166 | | |
1167 | | void Logger::info(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1168 | | { |
1169 | | if (isInfoEnabled()) |
1170 | | { |
1171 | | forcedLog(m_priv->levelData->Info, msg, location); |
1172 | | } |
1173 | | } |
1174 | | |
1175 | | void Logger::info(const std::basic_string<UniChar>& msg) const |
1176 | | { |
1177 | | if (isInfoEnabled()) |
1178 | | { |
1179 | | forcedLog(m_priv->levelData->Info, msg); |
1180 | | } |
1181 | | } |
1182 | | |
1183 | | void Logger::log(const LevelPtr& level1, const std::basic_string<UniChar>& message, |
1184 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
1185 | | { |
1186 | | if (isEnabledFor(level1)) |
1187 | | { |
1188 | | forcedLog(level1, message, location); |
1189 | | } |
1190 | | } |
1191 | | |
1192 | | void Logger::log(const LevelPtr& level1, const std::basic_string<UniChar>& message) const |
1193 | | { |
1194 | | if (isEnabledFor(level1)) |
1195 | | { |
1196 | | forcedLog(level1, message); |
1197 | | } |
1198 | | } |
1199 | | |
1200 | | void Logger::warn(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1201 | | { |
1202 | | if (isWarnEnabled()) |
1203 | | { |
1204 | | forcedLog(m_priv->levelData->Warn, msg, location); |
1205 | | } |
1206 | | } |
1207 | | |
1208 | | void Logger::warn(const std::basic_string<UniChar>& msg) const |
1209 | | { |
1210 | | if (isWarnEnabled()) |
1211 | | { |
1212 | | forcedLog(m_priv->levelData->Warn, msg); |
1213 | | } |
1214 | | } |
1215 | | |
1216 | | #endif |
1217 | | |
1218 | | |
1219 | | #if LOG4CXX_CFSTRING_API |
1220 | | void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message, |
1221 | | const LocationInfo& location) const |
1222 | | { |
1223 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1224 | | return; |
1225 | | LOG4CXX_DECODE_CFSTRING(msg, message); |
1226 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
1227 | | Pool p; |
1228 | | callAppenders(event, p); |
1229 | | } |
1230 | | |
1231 | | void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message) const |
1232 | | { |
1233 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1234 | | return; |
1235 | | LOG4CXX_DECODE_CFSTRING(msg, message); |
1236 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, msg, |
1237 | | LocationInfo::getLocationUnavailable()); |
1238 | | Pool p; |
1239 | | callAppenders(event, p); |
1240 | | } |
1241 | | |
1242 | | void Logger::getName(CFStringRef& rv) const |
1243 | | { |
1244 | | rv = Transcoder::encode(m_priv->name); |
1245 | | } |
1246 | | |
1247 | | LoggerPtr Logger::getLogger(const CFStringRef& name) |
1248 | | { |
1249 | | return LogManager::getLogger(name); |
1250 | | } |
1251 | | |
1252 | | void Logger::trace(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1253 | | { |
1254 | | if (isTraceEnabled()) |
1255 | | { |
1256 | | forcedLog(m_priv->levelData->Trace, msg, location); |
1257 | | } |
1258 | | } |
1259 | | |
1260 | | |
1261 | | void Logger::trace(const CFStringRef& msg) const |
1262 | | { |
1263 | | if (isTraceEnabled()) |
1264 | | { |
1265 | | forcedLog(m_priv->levelData->Trace, msg); |
1266 | | } |
1267 | | } |
1268 | | |
1269 | | void Logger::debug(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1270 | | { |
1271 | | if (isDebugEnabled()) |
1272 | | { |
1273 | | forcedLog(m_priv->levelData->Debug, msg, location); |
1274 | | } |
1275 | | } |
1276 | | |
1277 | | void Logger::debug(const CFStringRef& msg) const |
1278 | | { |
1279 | | if (isDebugEnabled()) |
1280 | | { |
1281 | | forcedLog(m_priv->levelData->Debug, msg); |
1282 | | } |
1283 | | } |
1284 | | |
1285 | | void Logger::error(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1286 | | { |
1287 | | if (isErrorEnabled()) |
1288 | | { |
1289 | | forcedLog(m_priv->levelData->Error, msg, location); |
1290 | | } |
1291 | | } |
1292 | | |
1293 | | void Logger::error(const CFStringRef& msg) const |
1294 | | { |
1295 | | if (isErrorEnabled()) |
1296 | | { |
1297 | | forcedLog(m_priv->levelData->Error, msg); |
1298 | | } |
1299 | | } |
1300 | | |
1301 | | void Logger::fatal(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1302 | | { |
1303 | | if (isFatalEnabled()) |
1304 | | { |
1305 | | forcedLog(m_priv->levelData->Fatal, msg, location); |
1306 | | } |
1307 | | } |
1308 | | |
1309 | | void Logger::fatal(const CFStringRef& msg) const |
1310 | | { |
1311 | | if (isFatalEnabled()) |
1312 | | { |
1313 | | forcedLog(m_priv->levelData->Fatal, msg); |
1314 | | } |
1315 | | } |
1316 | | |
1317 | | void Logger::info(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1318 | | { |
1319 | | if (isInfoEnabled()) |
1320 | | { |
1321 | | forcedLog(m_priv->levelData->Info, msg, location); |
1322 | | } |
1323 | | } |
1324 | | |
1325 | | void Logger::info(const CFStringRef& msg) const |
1326 | | { |
1327 | | if (isInfoEnabled()) |
1328 | | { |
1329 | | forcedLog(m_priv->levelData->Info, msg); |
1330 | | } |
1331 | | } |
1332 | | |
1333 | | void Logger::log(const LevelPtr& level1, const CFStringRef& message, |
1334 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
1335 | | { |
1336 | | if (isEnabledFor(level1)) |
1337 | | { |
1338 | | forcedLog(level1, message, location); |
1339 | | } |
1340 | | } |
1341 | | |
1342 | | void Logger::log(const LevelPtr& level1, const CFStringRef& message) const |
1343 | | { |
1344 | | if (isEnabledFor(level1)) |
1345 | | { |
1346 | | forcedLog(level1, message); |
1347 | | } |
1348 | | } |
1349 | | |
1350 | | void Logger::warn(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1351 | | { |
1352 | | if (isWarnEnabled()) |
1353 | | { |
1354 | | forcedLog(m_priv->levelData->Warn, msg, location); |
1355 | | } |
1356 | | } |
1357 | | |
1358 | | void Logger::warn(const CFStringRef& msg) const |
1359 | | { |
1360 | | if (isWarnEnabled()) |
1361 | | { |
1362 | | forcedLog(m_priv->levelData->Warn, msg); |
1363 | | } |
1364 | | } |
1365 | | |
1366 | | #endif |
1367 | | |
1368 | | |