/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, Pool& p) 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, p); |
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 | | |
168 | | void Logger::closeNestedAppenders() |
169 | 0 | { |
170 | 0 | for (auto& item : getAllAppenders()) |
171 | 0 | { |
172 | 0 | item->close(); |
173 | 0 | } |
174 | 0 | } |
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 | 0 | { |
187 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
188 | 0 | return; |
189 | 0 | #if LOG4CXX_LOGCHAR_IS_UTF8 |
190 | 0 | 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 | 0 | Pool p; |
196 | 0 | callAppenders(event, p); |
197 | 0 | } |
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 | 0 | { |
241 | 0 | addEvent(m_priv->levelData->Debug, std::move(message), location); |
242 | 0 | } |
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 | 0 | { |
306 | 0 | return m_priv->aai.getAllAppenders(); |
307 | 0 | } |
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 | 0 | { |
316 | 0 | for (const Logger* l = this; l != 0; l = l->m_priv->parent.get()) |
317 | 0 | { |
318 | 0 | if (l->m_priv->level != 0) |
319 | 0 | { |
320 | 0 | return l->m_priv->level; |
321 | 0 | } |
322 | 0 | } |
323 | | |
324 | 0 | throw NullPointerException(LOG4CXX_STR("Logger level")); |
325 | | #if LOG4CXX_RETURN_AFTER_THROW |
326 | | return m_priv->level; |
327 | | #endif |
328 | 0 | } |
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 | 0 | { |
344 | 0 | return m_priv->repositoryRaw; |
345 | 0 | } |
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 | 0 | { |
396 | 0 | return m_priv->level; |
397 | 0 | } |
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::isThresholdEqualTo(const LevelPtr& level) const |
405 | 0 | { |
406 | 0 | return level->toInt() == m_threshold; |
407 | 0 | } |
408 | | |
409 | | bool Logger::isThresholdEqualTo(const LoggerPtr& other) const |
410 | 0 | { |
411 | 0 | return other->m_threshold == m_threshold; |
412 | 0 | } |
413 | | |
414 | | bool Logger::isThresholdValid() const |
415 | 0 | { |
416 | 0 | return getEffectiveLevel()->toInt() == m_threshold; |
417 | 0 | } |
418 | | |
419 | | bool Logger::isTraceEnabled() const |
420 | 0 | { |
421 | 0 | auto rep = getHierarchy(); |
422 | |
|
423 | 0 | if (!rep || rep->isDisabled(Level::TRACE_INT)) |
424 | 0 | { |
425 | 0 | return false; |
426 | 0 | } |
427 | | |
428 | 0 | return m_threshold <= Level::TRACE_INT; |
429 | 0 | } |
430 | | |
431 | | bool Logger::isDebugEnabled() const |
432 | 0 | { |
433 | 0 | auto rep = getHierarchy(); |
434 | |
|
435 | 0 | if (!rep || rep->isDisabled(Level::DEBUG_INT)) |
436 | 0 | { |
437 | 0 | return false; |
438 | 0 | } |
439 | | |
440 | 0 | return m_threshold <= Level::DEBUG_INT; |
441 | 0 | } |
442 | | |
443 | | bool Logger::isEnabledFor(const LevelPtr& level1) const |
444 | 0 | { |
445 | 0 | auto rep = getHierarchy(); |
446 | |
|
447 | 0 | if (!rep || rep->isDisabled(level1->toInt())) |
448 | 0 | { |
449 | 0 | return false; |
450 | 0 | } |
451 | | |
452 | 0 | return level1->isGreaterOrEqual(getEffectiveLevel()); |
453 | 0 | } |
454 | | |
455 | | |
456 | | bool Logger::isInfoEnabled() const |
457 | 0 | { |
458 | 0 | auto rep = getHierarchy(); |
459 | |
|
460 | 0 | if (!rep || rep->isDisabled(Level::INFO_INT)) |
461 | 0 | { |
462 | 0 | return false; |
463 | 0 | } |
464 | | |
465 | 0 | return m_threshold <= Level::INFO_INT; |
466 | 0 | } |
467 | | |
468 | | bool Logger::isErrorEnabled() const |
469 | 0 | { |
470 | 0 | auto rep = getHierarchy(); |
471 | |
|
472 | 0 | if (!rep || rep->isDisabled(Level::ERROR_INT)) |
473 | 0 | { |
474 | 0 | return false; |
475 | 0 | } |
476 | | |
477 | 0 | return m_threshold <= Level::ERROR_INT; |
478 | 0 | } |
479 | | |
480 | | bool Logger::isWarnEnabled() const |
481 | 0 | { |
482 | 0 | auto rep = getHierarchy(); |
483 | |
|
484 | 0 | if (!rep || rep->isDisabled(Level::WARN_INT)) |
485 | 0 | { |
486 | 0 | return false; |
487 | 0 | } |
488 | | |
489 | 0 | return m_threshold <= Level::WARN_INT; |
490 | 0 | } |
491 | | |
492 | | bool Logger::isFatalEnabled() const |
493 | 0 | { |
494 | 0 | auto rep = getHierarchy(); |
495 | |
|
496 | 0 | if (!rep || rep->isDisabled(Level::FATAL_INT)) |
497 | 0 | { |
498 | 0 | return false; |
499 | 0 | } |
500 | | |
501 | 0 | return m_threshold <= Level::FATAL_INT; |
502 | 0 | } |
503 | | |
504 | | /*void Logger::l7dlog(const LevelPtr& level, const String& key, |
505 | | const char* file, int line) |
506 | | { |
507 | | auto rep = getHierarchy(); |
508 | | |
509 | | if (!rep || rep->isDisabled(level->level)) |
510 | | { |
511 | | return; |
512 | | } |
513 | | |
514 | | if (level->isGreaterOrEqual(getEffectiveLevel())) |
515 | | { |
516 | | String msg = getResourceBundleString(key); |
517 | | |
518 | | // if message corresponding to 'key' could not be found in the |
519 | | // resource bundle, then default to 'key'. |
520 | | if (msg.empty()) |
521 | | { |
522 | | msg = key; |
523 | | } |
524 | | |
525 | | forcedLog(FQCN, level, msg, file, line); |
526 | | } |
527 | | }*/ |
528 | | |
529 | | |
530 | | |
531 | | void Logger::l7dlog(const LevelPtr& level1, const LogString& key, |
532 | | const LocationInfo& location, const std::vector<LogString>& params) const |
533 | 0 | { |
534 | 0 | auto rep = getHierarchy(); |
535 | |
|
536 | 0 | if (!rep || rep->isDisabled(level1->toInt())) |
537 | 0 | { |
538 | 0 | return; |
539 | 0 | } |
540 | | |
541 | 0 | if (level1->isGreaterOrEqual(getEffectiveLevel())) |
542 | 0 | { |
543 | 0 | LogString pattern = getResourceBundleString(key); |
544 | 0 | LogString msg; |
545 | |
|
546 | 0 | if (pattern.empty()) |
547 | 0 | { |
548 | 0 | msg = key; |
549 | 0 | } |
550 | 0 | else |
551 | 0 | { |
552 | 0 | msg = StringHelper::format(pattern, params); |
553 | 0 | } |
554 | |
|
555 | 0 | addEventLS(level1, std::move(msg), location); |
556 | 0 | } |
557 | 0 | } |
558 | | |
559 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
560 | | const LocationInfo& location) const |
561 | 0 | { |
562 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
563 | |
|
564 | 0 | std::vector<LogString> values(0); |
565 | 0 | l7dlog(level1, lkey, location, values); |
566 | 0 | } |
567 | | |
568 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
569 | | const LocationInfo& location, const std::string& val1) const |
570 | 0 | { |
571 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
572 | 0 | LOG4CXX_DECODE_CHAR(lval1, val1); |
573 | |
|
574 | 0 | std::vector<LogString> values(1); |
575 | 0 | values[0] = lval1; |
576 | 0 | l7dlog(level1, lkey, location, values); |
577 | 0 | } |
578 | | |
579 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
580 | | const LocationInfo& location, |
581 | | const std::string& val1, const std::string& val2) const |
582 | 0 | { |
583 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
584 | 0 | LOG4CXX_DECODE_CHAR(lval1, val1); |
585 | 0 | LOG4CXX_DECODE_CHAR(lval2, val2); |
586 | |
|
587 | 0 | std::vector<LogString> values(2); |
588 | 0 | values[0] = lval1; |
589 | 0 | values[1] = lval2; |
590 | 0 | l7dlog(level1, lkey, location, values); |
591 | 0 | } |
592 | | |
593 | | void Logger::l7dlog(const LevelPtr& level1, const std::string& key, |
594 | | const LocationInfo& location, |
595 | | const std::string& val1, const std::string& val2, const std::string& val3) const |
596 | 0 | { |
597 | 0 | LOG4CXX_DECODE_CHAR(lkey, key); |
598 | 0 | LOG4CXX_DECODE_CHAR(lval1, val1); |
599 | 0 | LOG4CXX_DECODE_CHAR(lval2, val2); |
600 | 0 | LOG4CXX_DECODE_CHAR(lval3, val3); |
601 | |
|
602 | 0 | std::vector<LogString> values(3); |
603 | 0 | values[0] = lval1; |
604 | 0 | values[1] = lval2; |
605 | 0 | values[2] = lval3; |
606 | 0 | l7dlog(level1, lkey, location, values); |
607 | 0 | } |
608 | | |
609 | | void Logger::removeAllAppenders() |
610 | 0 | { |
611 | 0 | AppenderList currentAppenders = m_priv->aai.getAllAppenders(); |
612 | 0 | m_priv->aai.removeAllAppenders(); |
613 | |
|
614 | 0 | auto rep = getHierarchy(); |
615 | 0 | if(rep){ |
616 | 0 | for(AppenderPtr appender : currentAppenders){ |
617 | 0 | rep->fireRemoveAppenderEvent(this, appender.get()); |
618 | 0 | } |
619 | 0 | } |
620 | 0 | } |
621 | | |
622 | | void Logger::removeAppender(const AppenderPtr appender) |
623 | 0 | { |
624 | 0 | m_priv->aai.removeAppender(appender); |
625 | 0 | if (auto rep = getHierarchy()) |
626 | 0 | { |
627 | 0 | rep->fireRemoveAppenderEvent(this, appender.get()); |
628 | 0 | } |
629 | 0 | } |
630 | | |
631 | | void Logger::removeAppender(const LogString& name1) |
632 | 0 | { |
633 | 0 | AppenderPtr appender = m_priv->aai.getAppender(name1); |
634 | 0 | if(appender){ |
635 | 0 | removeAppender(appender); |
636 | 0 | } |
637 | 0 | } |
638 | | |
639 | | void Logger::removeHierarchy() |
640 | 0 | { |
641 | 0 | m_priv->repositoryRaw = 0; |
642 | 0 | } |
643 | | |
644 | | void Logger::setAdditivity(bool additive1) |
645 | 0 | { |
646 | 0 | m_priv->additive = additive1; |
647 | 0 | } |
648 | | |
649 | | void Logger::setHierarchy(spi::LoggerRepository* repository1) |
650 | 0 | { |
651 | 0 | m_priv->repositoryRaw = repository1; |
652 | 0 | } |
653 | | |
654 | | void Logger::setParent(LoggerPtr parentLogger) |
655 | 0 | { |
656 | 0 | m_priv->parent = parentLogger; |
657 | 0 | updateThreshold(); |
658 | 0 | if (auto rep = dynamic_cast<Hierarchy*>(getHierarchy())) |
659 | 0 | rep->updateChildren(this); |
660 | 0 | } |
661 | | |
662 | | void Logger::setLevel(const LevelPtr level1) |
663 | 0 | { |
664 | 0 | if (m_priv->level != level1) |
665 | 0 | { |
666 | 0 | m_priv->level = level1; |
667 | 0 | updateThreshold(); |
668 | 0 | if (auto rep = dynamic_cast<Hierarchy*>(getHierarchy())) |
669 | 0 | rep->updateChildren(this); |
670 | 0 | } |
671 | 0 | } |
672 | | |
673 | | void Logger::updateThreshold() |
674 | 0 | { |
675 | 0 | m_threshold = getEffectiveLevel()->toInt(); |
676 | 0 | } |
677 | | |
678 | | const LogString& Logger::getName() const |
679 | 0 | { |
680 | 0 | return m_priv->name; |
681 | 0 | } |
682 | | |
683 | | LoggerPtr Logger::getLogger(const std::string& name) |
684 | 0 | { |
685 | 0 | return LogManager::getLogger(name); |
686 | 0 | } |
687 | | |
688 | | |
689 | | LoggerPtr Logger::getLogger(const char* const name) |
690 | 0 | { |
691 | 0 | return LogManager::getLogger(name); |
692 | 0 | } |
693 | | |
694 | | void Logger::setResourceBundle(const helpers::ResourceBundlePtr& bundle) |
695 | 0 | { |
696 | 0 | m_priv->resourceBundle = bundle; |
697 | 0 | } |
698 | | |
699 | | LoggerPtr Logger::getRootLogger() |
700 | 0 | { |
701 | 0 | return LogManager::getRootLogger(); |
702 | 0 | } |
703 | | |
704 | | LoggerPtr Logger::getLoggerLS(const LogString& name, |
705 | | const spi::LoggerFactoryPtr& factory) |
706 | 0 | { |
707 | 0 | return LogManager::getLoggerLS(name, factory); |
708 | 0 | } |
709 | | |
710 | | void Logger::getName(std::string& rv) const |
711 | 0 | { |
712 | 0 | Transcoder::encode(m_priv->name, rv); |
713 | 0 | } |
714 | | |
715 | | |
716 | | void Logger::trace(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
717 | 0 | { |
718 | 0 | if (isTraceEnabled()) |
719 | 0 | { |
720 | 0 | forcedLog(m_priv->levelData->Trace, msg, location); |
721 | 0 | } |
722 | 0 | } |
723 | | |
724 | | |
725 | | void Logger::trace(const std::string& msg) const |
726 | 0 | { |
727 | 0 | if (isTraceEnabled()) |
728 | 0 | { |
729 | 0 | forcedLog(m_priv->levelData->Trace, msg); |
730 | 0 | } |
731 | 0 | } |
732 | | |
733 | | void Logger::debug(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
734 | 0 | { |
735 | 0 | if (isDebugEnabled()) |
736 | 0 | { |
737 | 0 | forcedLog(m_priv->levelData->Debug, msg, location); |
738 | 0 | } |
739 | 0 | } |
740 | | |
741 | | void Logger::debug(const std::string& msg) const |
742 | 0 | { |
743 | 0 | if (isDebugEnabled()) |
744 | 0 | { |
745 | 0 | forcedLog(m_priv->levelData->Debug, msg); |
746 | 0 | } |
747 | 0 | } |
748 | | |
749 | | |
750 | | void Logger::error(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
751 | 0 | { |
752 | 0 | if (isErrorEnabled()) |
753 | 0 | { |
754 | 0 | forcedLog(m_priv->levelData->Error, msg, location); |
755 | 0 | } |
756 | 0 | } |
757 | | |
758 | | |
759 | | void Logger::error(const std::string& msg) const |
760 | 0 | { |
761 | 0 | if (isErrorEnabled()) |
762 | 0 | { |
763 | 0 | forcedLog(m_priv->levelData->Error, msg); |
764 | 0 | } |
765 | 0 | } |
766 | | |
767 | | void Logger::fatal(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
768 | 0 | { |
769 | 0 | if (isFatalEnabled()) |
770 | 0 | { |
771 | 0 | forcedLog(m_priv->levelData->Fatal, msg, location); |
772 | 0 | } |
773 | 0 | } |
774 | | |
775 | | void Logger::fatal(const std::string& msg) const |
776 | 0 | { |
777 | 0 | if (isFatalEnabled()) |
778 | 0 | { |
779 | 0 | forcedLog(m_priv->levelData->Fatal, msg); |
780 | 0 | } |
781 | 0 | } |
782 | | |
783 | | void Logger::info(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
784 | 0 | { |
785 | 0 | if (isInfoEnabled()) |
786 | 0 | { |
787 | 0 | forcedLog(m_priv->levelData->Info, msg, location); |
788 | 0 | } |
789 | 0 | } |
790 | | |
791 | | void Logger::info(const std::string& msg) const |
792 | 0 | { |
793 | 0 | if (isInfoEnabled()) |
794 | 0 | { |
795 | 0 | forcedLog(m_priv->levelData->Info, msg); |
796 | 0 | } |
797 | 0 | } |
798 | | |
799 | | void Logger::log(const LevelPtr& level1, const std::string& message, |
800 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
801 | 0 | { |
802 | 0 | if (isEnabledFor(level1)) |
803 | 0 | { |
804 | 0 | forcedLog(level1, message, location); |
805 | 0 | } |
806 | 0 | } |
807 | | |
808 | | void Logger::log(const LevelPtr& level1, const std::string& message) const |
809 | 0 | { |
810 | 0 | if (isEnabledFor(level1)) |
811 | 0 | { |
812 | 0 | forcedLog(level1, message); |
813 | 0 | } |
814 | 0 | } |
815 | | |
816 | | void Logger::logLS(const LevelPtr& level1, const LogString& message, |
817 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
818 | 0 | { |
819 | 0 | if (isEnabledFor(level1)) |
820 | 0 | { |
821 | 0 | forcedLogLS(level1, message, location); |
822 | 0 | } |
823 | 0 | } |
824 | | |
825 | | void Logger::warn(const std::string& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
826 | 0 | { |
827 | 0 | if (isWarnEnabled()) |
828 | 0 | { |
829 | 0 | forcedLog(m_priv->levelData->Warn, msg, location); |
830 | 0 | } |
831 | 0 | } |
832 | | |
833 | | void Logger::warn(const std::string& msg) const |
834 | 0 | { |
835 | 0 | if (isWarnEnabled()) |
836 | 0 | { |
837 | 0 | forcedLog(m_priv->levelData->Warn, msg); |
838 | 0 | } |
839 | 0 | } |
840 | | |
841 | | LoggerPtr Logger::getLoggerLS(const LogString& name) |
842 | 0 | { |
843 | 0 | return LogManager::getLoggerLS(name); |
844 | 0 | } |
845 | | |
846 | | |
847 | | |
848 | | |
849 | | #if LOG4CXX_WCHAR_T_API |
850 | | void Logger::addEvent(const LevelPtr& level, std::wstring&& message, const LocationInfo& location) const |
851 | 0 | { |
852 | 0 | if (!getHierarchy()) // Has removeHierarchy() been called? |
853 | 0 | return; |
854 | | #if LOG4CXX_LOGCHAR_IS_WCHAR |
855 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(message)); |
856 | | #else |
857 | 0 | LOG4CXX_DECODE_WCHAR(msg, message); |
858 | 0 | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
859 | 0 | #endif |
860 | 0 | Pool p; |
861 | 0 | callAppenders(event, p); |
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 | Pool p; |
906 | 0 | callAppenders(event, p); |
907 | 0 | } |
908 | | |
909 | | void Logger::forcedLog(const LevelPtr& level1, const std::wstring& message) const |
910 | 0 | { |
911 | 0 | forcedLog(level1, message, LocationInfo::getLocationUnavailable()); |
912 | 0 | } |
913 | | |
914 | | void Logger::getName(std::wstring& rv) const |
915 | 0 | { |
916 | 0 | Transcoder::encode(m_priv->name, rv); |
917 | 0 | } |
918 | | |
919 | | LoggerPtr Logger::getLogger(const std::wstring& name) |
920 | 0 | { |
921 | 0 | return LogManager::getLogger(name); |
922 | 0 | } |
923 | | |
924 | | LoggerPtr Logger::getLogger(const wchar_t* const name) |
925 | 0 | { |
926 | 0 | return LogManager::getLogger(name); |
927 | 0 | } |
928 | | |
929 | | void Logger::trace(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
930 | 0 | { |
931 | 0 | if (isTraceEnabled()) |
932 | 0 | { |
933 | 0 | forcedLog(m_priv->levelData->Trace, msg, location); |
934 | 0 | } |
935 | 0 | } |
936 | | |
937 | | |
938 | | void Logger::trace(const std::wstring& msg) const |
939 | 0 | { |
940 | 0 | if (isTraceEnabled()) |
941 | 0 | { |
942 | 0 | forcedLog(m_priv->levelData->Trace, msg); |
943 | 0 | } |
944 | 0 | } |
945 | | |
946 | | void Logger::debug(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
947 | 0 | { |
948 | 0 | if (isDebugEnabled()) |
949 | 0 | { |
950 | 0 | forcedLog(m_priv->levelData->Debug, msg, location); |
951 | 0 | } |
952 | 0 | } |
953 | | |
954 | | void Logger::debug(const std::wstring& msg) const |
955 | 0 | { |
956 | 0 | if (isDebugEnabled()) |
957 | 0 | { |
958 | 0 | forcedLog(m_priv->levelData->Debug, msg); |
959 | 0 | } |
960 | 0 | } |
961 | | |
962 | | void Logger::error(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
963 | 0 | { |
964 | 0 | if (isErrorEnabled()) |
965 | 0 | { |
966 | 0 | forcedLog(m_priv->levelData->Error, msg, location); |
967 | 0 | } |
968 | 0 | } |
969 | | |
970 | | void Logger::error(const std::wstring& msg) const |
971 | 0 | { |
972 | 0 | if (isErrorEnabled()) |
973 | 0 | { |
974 | 0 | forcedLog(m_priv->levelData->Error, msg); |
975 | 0 | } |
976 | 0 | } |
977 | | |
978 | | void Logger::fatal(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
979 | 0 | { |
980 | 0 | if (isFatalEnabled()) |
981 | 0 | { |
982 | 0 | forcedLog(m_priv->levelData->Fatal, msg, location); |
983 | 0 | } |
984 | 0 | } |
985 | | |
986 | | void Logger::fatal(const std::wstring& msg) const |
987 | 0 | { |
988 | 0 | if (isFatalEnabled()) |
989 | 0 | { |
990 | 0 | forcedLog(m_priv->levelData->Fatal, msg); |
991 | 0 | } |
992 | 0 | } |
993 | | |
994 | | void Logger::info(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
995 | 0 | { |
996 | 0 | if (isInfoEnabled()) |
997 | 0 | { |
998 | 0 | forcedLog(m_priv->levelData->Info, msg, location); |
999 | 0 | } |
1000 | 0 | } |
1001 | | |
1002 | | void Logger::info(const std::wstring& msg) const |
1003 | 0 | { |
1004 | 0 | if (isInfoEnabled()) |
1005 | 0 | { |
1006 | 0 | forcedLog(m_priv->levelData->Info, msg); |
1007 | 0 | } |
1008 | 0 | } |
1009 | | |
1010 | | void Logger::log(const LevelPtr& level1, const std::wstring& message, |
1011 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
1012 | 0 | { |
1013 | 0 | if (isEnabledFor(level1)) |
1014 | 0 | { |
1015 | 0 | forcedLog(level1, message, location); |
1016 | 0 | } |
1017 | 0 | } |
1018 | | |
1019 | | void Logger::log(const LevelPtr& level1, const std::wstring& message) const |
1020 | 0 | { |
1021 | 0 | if (isEnabledFor(level1)) |
1022 | 0 | { |
1023 | 0 | forcedLog(level1, message); |
1024 | 0 | } |
1025 | 0 | } |
1026 | | |
1027 | | void Logger::warn(const std::wstring& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1028 | 0 | { |
1029 | 0 | if (isWarnEnabled()) |
1030 | 0 | { |
1031 | 0 | forcedLog(m_priv->levelData->Warn, msg, location); |
1032 | 0 | } |
1033 | 0 | } |
1034 | | |
1035 | | void Logger::warn(const std::wstring& msg) const |
1036 | 0 | { |
1037 | 0 | if (isWarnEnabled()) |
1038 | 0 | { |
1039 | 0 | forcedLog(m_priv->levelData->Warn, msg); |
1040 | 0 | } |
1041 | 0 | } |
1042 | | |
1043 | | #endif |
1044 | | |
1045 | | |
1046 | | #if LOG4CXX_UNICHAR_API |
1047 | | void Logger::addEvent(const LevelPtr& level1, std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1048 | | { |
1049 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1050 | | return; |
1051 | | LOG4CXX_DECODE_UNICHAR(msg, message); |
1052 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg)); |
1053 | | Pool p; |
1054 | | callAppenders(event, p); |
1055 | | } |
1056 | | |
1057 | | void Logger::addFatalEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1058 | | { |
1059 | | addEvent(m_priv->levelData->Fatal, std::move(message), location); |
1060 | | } |
1061 | | |
1062 | | void Logger::addErrorEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1063 | | { |
1064 | | addEvent(m_priv->levelData->Error, std::move(message), location); |
1065 | | } |
1066 | | |
1067 | | void Logger::addWarnEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1068 | | { |
1069 | | addEvent(m_priv->levelData->Warn, std::move(message), location); |
1070 | | } |
1071 | | |
1072 | | void Logger::addInfoEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1073 | | { |
1074 | | addEvent(m_priv->levelData->Info, std::move(message), location); |
1075 | | } |
1076 | | |
1077 | | void Logger::addDebugEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1078 | | { |
1079 | | addEvent(m_priv->levelData->Debug, std::move(message), location); |
1080 | | } |
1081 | | |
1082 | | void Logger::addTraceEvent(std::basic_string<UniChar>&& message, const LocationInfo& location) const |
1083 | | { |
1084 | | addEvent(m_priv->levelData->Trace, std::move(message), location); |
1085 | | } |
1086 | | |
1087 | | void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message, |
1088 | | const LocationInfo& location) const |
1089 | | { |
1090 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1091 | | return; |
1092 | | LOG4CXX_DECODE_UNICHAR(msg, message); |
1093 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg)); |
1094 | | Pool p; |
1095 | | callAppenders(event, p); |
1096 | | } |
1097 | | |
1098 | | void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message) const |
1099 | | { |
1100 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1101 | | return; |
1102 | | LOG4CXX_DECODE_UNICHAR(msg, message); |
1103 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, msg, |
1104 | | LocationInfo::getLocationUnavailable()); |
1105 | | Pool p; |
1106 | | callAppenders(event, p); |
1107 | | } |
1108 | | |
1109 | | void Logger::getName(std::basic_string<UniChar>& rv) const |
1110 | | { |
1111 | | Transcoder::encode(m_priv->name, rv); |
1112 | | } |
1113 | | |
1114 | | LoggerPtr Logger::getLogger(const std::basic_string<UniChar>& name) |
1115 | | { |
1116 | | return LogManager::getLogger(name); |
1117 | | } |
1118 | | |
1119 | | void Logger::trace(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1120 | | { |
1121 | | if (isTraceEnabled()) |
1122 | | { |
1123 | | forcedLog(m_priv->levelData->Trace, msg, location); |
1124 | | } |
1125 | | } |
1126 | | |
1127 | | |
1128 | | void Logger::trace(const std::basic_string<UniChar>& msg) const |
1129 | | { |
1130 | | if (isTraceEnabled()) |
1131 | | { |
1132 | | forcedLog(m_priv->levelData->Trace, msg); |
1133 | | } |
1134 | | } |
1135 | | |
1136 | | void Logger::debug(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1137 | | { |
1138 | | if (isDebugEnabled()) |
1139 | | { |
1140 | | forcedLog(m_priv->levelData->Debug, msg, location); |
1141 | | } |
1142 | | } |
1143 | | |
1144 | | void Logger::debug(const std::basic_string<UniChar>& msg) const |
1145 | | { |
1146 | | if (isDebugEnabled()) |
1147 | | { |
1148 | | forcedLog(m_priv->levelData->Debug, msg); |
1149 | | } |
1150 | | } |
1151 | | |
1152 | | void Logger::error(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1153 | | { |
1154 | | if (isErrorEnabled()) |
1155 | | { |
1156 | | forcedLog(m_priv->levelData->Error, msg, location); |
1157 | | } |
1158 | | } |
1159 | | |
1160 | | void Logger::error(const std::basic_string<UniChar>& msg) const |
1161 | | { |
1162 | | if (isErrorEnabled()) |
1163 | | { |
1164 | | forcedLog(m_priv->levelData->Error, msg); |
1165 | | } |
1166 | | } |
1167 | | |
1168 | | void Logger::fatal(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1169 | | { |
1170 | | if (isFatalEnabled()) |
1171 | | { |
1172 | | forcedLog(m_priv->levelData->Fatal, msg, location); |
1173 | | } |
1174 | | } |
1175 | | |
1176 | | void Logger::fatal(const std::basic_string<UniChar>& msg) const |
1177 | | { |
1178 | | if (isFatalEnabled()) |
1179 | | { |
1180 | | forcedLog(m_priv->levelData->Fatal, msg); |
1181 | | } |
1182 | | } |
1183 | | |
1184 | | void Logger::info(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1185 | | { |
1186 | | if (isInfoEnabled()) |
1187 | | { |
1188 | | forcedLog(m_priv->levelData->Info, msg, location); |
1189 | | } |
1190 | | } |
1191 | | |
1192 | | void Logger::info(const std::basic_string<UniChar>& msg) const |
1193 | | { |
1194 | | if (isInfoEnabled()) |
1195 | | { |
1196 | | forcedLog(m_priv->levelData->Info, msg); |
1197 | | } |
1198 | | } |
1199 | | |
1200 | | void Logger::log(const LevelPtr& level1, const std::basic_string<UniChar>& message, |
1201 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
1202 | | { |
1203 | | if (isEnabledFor(level1)) |
1204 | | { |
1205 | | forcedLog(level1, message, location); |
1206 | | } |
1207 | | } |
1208 | | |
1209 | | void Logger::log(const LevelPtr& level1, const std::basic_string<UniChar>& message) const |
1210 | | { |
1211 | | if (isEnabledFor(level1)) |
1212 | | { |
1213 | | forcedLog(level1, message); |
1214 | | } |
1215 | | } |
1216 | | |
1217 | | void Logger::warn(const std::basic_string<UniChar>& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1218 | | { |
1219 | | if (isWarnEnabled()) |
1220 | | { |
1221 | | forcedLog(m_priv->levelData->Warn, msg, location); |
1222 | | } |
1223 | | } |
1224 | | |
1225 | | void Logger::warn(const std::basic_string<UniChar>& msg) const |
1226 | | { |
1227 | | if (isWarnEnabled()) |
1228 | | { |
1229 | | forcedLog(m_priv->levelData->Warn, msg); |
1230 | | } |
1231 | | } |
1232 | | |
1233 | | #endif |
1234 | | |
1235 | | |
1236 | | #if LOG4CXX_CFSTRING_API |
1237 | | void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message, |
1238 | | const LocationInfo& location) const |
1239 | | { |
1240 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1241 | | return; |
1242 | | LOG4CXX_DECODE_CFSTRING(msg, message); |
1243 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg)); |
1244 | | Pool p; |
1245 | | callAppenders(event, p); |
1246 | | } |
1247 | | |
1248 | | void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message) const |
1249 | | { |
1250 | | if (!getHierarchy()) // Has removeHierarchy() been called? |
1251 | | return; |
1252 | | LOG4CXX_DECODE_CFSTRING(msg, message); |
1253 | | auto event = std::make_shared<LoggingEvent>(m_priv->name, level, msg, |
1254 | | LocationInfo::getLocationUnavailable()); |
1255 | | Pool p; |
1256 | | callAppenders(event, p); |
1257 | | } |
1258 | | |
1259 | | void Logger::getName(CFStringRef& rv) const |
1260 | | { |
1261 | | rv = Transcoder::encode(m_priv->name); |
1262 | | } |
1263 | | |
1264 | | LoggerPtr Logger::getLogger(const CFStringRef& name) |
1265 | | { |
1266 | | return LogManager::getLogger(name); |
1267 | | } |
1268 | | |
1269 | | void Logger::trace(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1270 | | { |
1271 | | if (isTraceEnabled()) |
1272 | | { |
1273 | | forcedLog(m_priv->levelData->Trace, msg, location); |
1274 | | } |
1275 | | } |
1276 | | |
1277 | | |
1278 | | void Logger::trace(const CFStringRef& msg) const |
1279 | | { |
1280 | | if (isTraceEnabled()) |
1281 | | { |
1282 | | forcedLog(m_priv->levelData->Trace, msg); |
1283 | | } |
1284 | | } |
1285 | | |
1286 | | void Logger::debug(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1287 | | { |
1288 | | if (isDebugEnabled()) |
1289 | | { |
1290 | | forcedLog(m_priv->levelData->Debug, msg, location); |
1291 | | } |
1292 | | } |
1293 | | |
1294 | | void Logger::debug(const CFStringRef& msg) const |
1295 | | { |
1296 | | if (isDebugEnabled()) |
1297 | | { |
1298 | | forcedLog(m_priv->levelData->Debug, msg); |
1299 | | } |
1300 | | } |
1301 | | |
1302 | | void Logger::error(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1303 | | { |
1304 | | if (isErrorEnabled()) |
1305 | | { |
1306 | | forcedLog(m_priv->levelData->Error, msg, location); |
1307 | | } |
1308 | | } |
1309 | | |
1310 | | void Logger::error(const CFStringRef& msg) const |
1311 | | { |
1312 | | if (isErrorEnabled()) |
1313 | | { |
1314 | | forcedLog(m_priv->levelData->Error, msg); |
1315 | | } |
1316 | | } |
1317 | | |
1318 | | void Logger::fatal(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1319 | | { |
1320 | | if (isFatalEnabled()) |
1321 | | { |
1322 | | forcedLog(m_priv->levelData->Fatal, msg, location); |
1323 | | } |
1324 | | } |
1325 | | |
1326 | | void Logger::fatal(const CFStringRef& msg) const |
1327 | | { |
1328 | | if (isFatalEnabled()) |
1329 | | { |
1330 | | forcedLog(m_priv->levelData->Fatal, msg); |
1331 | | } |
1332 | | } |
1333 | | |
1334 | | void Logger::info(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1335 | | { |
1336 | | if (isInfoEnabled()) |
1337 | | { |
1338 | | forcedLog(m_priv->levelData->Info, msg, location); |
1339 | | } |
1340 | | } |
1341 | | |
1342 | | void Logger::info(const CFStringRef& msg) const |
1343 | | { |
1344 | | if (isInfoEnabled()) |
1345 | | { |
1346 | | forcedLog(m_priv->levelData->Info, msg); |
1347 | | } |
1348 | | } |
1349 | | |
1350 | | void Logger::log(const LevelPtr& level1, const CFStringRef& message, |
1351 | | const LOG4CXX_NS::spi::LocationInfo& location) const |
1352 | | { |
1353 | | if (isEnabledFor(level1)) |
1354 | | { |
1355 | | forcedLog(level1, message, location); |
1356 | | } |
1357 | | } |
1358 | | |
1359 | | void Logger::log(const LevelPtr& level1, const CFStringRef& message) const |
1360 | | { |
1361 | | if (isEnabledFor(level1)) |
1362 | | { |
1363 | | forcedLog(level1, message); |
1364 | | } |
1365 | | } |
1366 | | |
1367 | | void Logger::warn(const CFStringRef& msg, const LOG4CXX_NS::spi::LocationInfo& location) const |
1368 | | { |
1369 | | if (isWarnEnabled()) |
1370 | | { |
1371 | | forcedLog(m_priv->levelData->Warn, msg, location); |
1372 | | } |
1373 | | } |
1374 | | |
1375 | | void Logger::warn(const CFStringRef& msg) const |
1376 | | { |
1377 | | if (isWarnEnabled()) |
1378 | | { |
1379 | | forcedLog(m_priv->levelData->Warn, msg); |
1380 | | } |
1381 | | } |
1382 | | |
1383 | | #endif |
1384 | | |
1385 | | |