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