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