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