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/logstring.h>
19 #include <log4cxx/logger.h>
20 #include <log4cxx/spi/loggingevent.h>
21 #include <log4cxx/logmanager.h>
22 #include <log4cxx/spi/loggerfactory.h>
23 #include <log4cxx/appender.h>
24 #include <log4cxx/level.h>
25 #include <log4cxx/helpers/loglog.h>
26 #include <log4cxx/spi/loggerrepository.h>
27 #include <log4cxx/helpers/stringhelper.h>
28 #include <log4cxx/helpers/synchronized.h>
29 #include <log4cxx/helpers/transcoder.h>
30 #include <log4cxx/helpers/appenderattachableimpl.h>
31 #include <log4cxx/helpers/exception.h>
32 #if !defined(LOG4CXX)
33 	#define LOG4CXX 1
34 #endif
35 #include <log4cxx/private/log4cxx_private.h>
36 #include <log4cxx/helpers/aprinitializer.h>
37 
38 using namespace log4cxx;
39 using namespace log4cxx::helpers;
40 using namespace log4cxx::spi;
41 
IMPLEMENT_LOG4CXX_OBJECT(Logger)42 IMPLEMENT_LOG4CXX_OBJECT(Logger)
43 
44 Logger::Logger(Pool& p, const LogString& name1)
45 	: pool(&p), name(), level(), parent(), resourceBundle(),
46 	  repository(), aai(), SHARED_MUTEX_INIT(mutex, p)
47 {
48 	name = name1;
49 	additive = true;
50 }
51 
~Logger()52 Logger::~Logger()
53 {
54 }
55 
addRef() const56 void Logger::addRef() const
57 {
58 	ObjectImpl::addRef();
59 }
60 
releaseRef() const61 void Logger::releaseRef() const
62 {
63 	ObjectImpl::releaseRef();
64 }
65 
addAppender(const AppenderPtr & newAppender)66 void Logger::addAppender(const AppenderPtr& newAppender)
67 {
68 	log4cxx::spi::LoggerRepository* rep = 0;
69 	{
70 		LOCK_W sync(mutex);
71 
72 		if (aai == 0)
73 		{
74 			aai = new AppenderAttachableImpl(*pool);
75 		}
76 
77 		aai->addAppender(newAppender);
78 		rep = repository;
79 	}
80 
81 	if (rep != 0)
82 	{
83 		rep->fireAddAppenderEvent(this, newAppender);
84 	}
85 }
86 
87 
callAppenders(const spi::LoggingEventPtr & event,Pool & p) const88 void Logger::callAppenders(const spi::LoggingEventPtr& event, Pool& p) const
89 {
90 	int writes = 0;
91 
92 	for (LoggerPtr logger(const_cast<Logger*>(this));
93 		logger != 0;
94 		logger = logger->parent)
95 	{
96 		// Protected against simultaneous call to addAppender, removeAppender,...
97 		LOCK_R sync(logger->mutex);
98 
99 		if (logger->aai != 0)
100 		{
101 			writes += logger->aai->appendLoopOnAppenders(event, p);
102 		}
103 
104 		if (!logger->additive)
105 		{
106 			break;
107 		}
108 	}
109 
110 	if (writes == 0 && repository != 0)
111 	{
112 		repository->emitNoAppenderWarning(const_cast<Logger*>(this));
113 	}
114 }
115 
closeNestedAppenders()116 void Logger::closeNestedAppenders()
117 {
118 	AppenderList appenders = getAllAppenders();
119 
120 	for (AppenderList::iterator it = appenders.begin(); it != appenders.end(); ++it)
121 	{
122 		(*it)->close();
123 	}
124 }
125 
126 
forcedLog(const LevelPtr & level1,const std::string & message,const LocationInfo & location) const127 void Logger::forcedLog(const LevelPtr& level1, const std::string& message,
128 	const LocationInfo& location) const
129 {
130 	Pool p;
131 	LOG4CXX_DECODE_CHAR(msg, message);
132 	LoggingEventPtr event(new LoggingEvent(name, level1, msg, location));
133 	callAppenders(event, p);
134 }
135 
136 
forcedLog(const LevelPtr & level1,const std::string & message) const137 void Logger::forcedLog(const LevelPtr& level1, const std::string& message) const
138 {
139 	Pool p;
140 	LOG4CXX_DECODE_CHAR(msg, message);
141 	LoggingEventPtr event(new LoggingEvent(name, level1, msg,
142 			LocationInfo::getLocationUnavailable()));
143 	callAppenders(event, p);
144 }
145 
forcedLogLS(const LevelPtr & level1,const LogString & message,const LocationInfo & location) const146 void Logger::forcedLogLS(const LevelPtr& level1, const LogString& message,
147 	const LocationInfo& location) const
148 {
149 	Pool p;
150 	LoggingEventPtr event(new LoggingEvent(name, level1, message, location));
151 	callAppenders(event, p);
152 }
153 
154 
getAdditivity() const155 bool Logger::getAdditivity() const
156 {
157 	return additive;
158 }
159 
getAllAppenders() const160 AppenderList Logger::getAllAppenders() const
161 {
162 	LOCK_W sync(mutex);
163 
164 	if (aai == 0)
165 	{
166 		return AppenderList();
167 	}
168 	else
169 	{
170 		return aai->getAllAppenders();
171 	}
172 }
173 
getAppender(const LogString & name1) const174 AppenderPtr Logger::getAppender(const LogString& name1) const
175 {
176 	LOCK_W sync(mutex);
177 
178 	if (aai == 0 || name1.empty())
179 	{
180 		return 0;
181 	}
182 
183 	return aai->getAppender(name1);
184 }
185 
getEffectiveLevel() const186 const LevelPtr& Logger::getEffectiveLevel() const
187 {
188 	for (const Logger* l = this; l != 0; l = l->parent)
189 	{
190 		if (l->level != 0)
191 		{
192 			return l->level;
193 		}
194 	}
195 
196 	throw NullPointerException(LOG4CXX_STR("No level specified for logger or ancestors."));
197 #if LOG4CXX_RETURN_AFTER_THROW
198 	return this->level;
199 #endif
200 }
201 
getLoggerRepository() const202 LoggerRepositoryPtr Logger::getLoggerRepository() const
203 {
204 	return repository;
205 }
206 
getResourceBundle() const207 ResourceBundlePtr Logger::getResourceBundle() const
208 {
209 	for (LoggerPtr l(const_cast<Logger*>(this)); l != 0; l = l->parent)
210 	{
211 		if (l->resourceBundle != 0)
212 		{
213 			return l->resourceBundle;
214 		}
215 	}
216 
217 	// It might be the case that there is no resource bundle
218 	return 0;
219 }
220 
221 
getResourceBundleString(const LogString & key) const222 LogString Logger::getResourceBundleString(const LogString& key) const
223 {
224 	ResourceBundlePtr rb = getResourceBundle();
225 
226 	// This is one of the rare cases where we can use logging in order
227 	// to report errors from within log4j.
228 	if (rb == 0)
229 	{
230 		return LogString();
231 	}
232 	else
233 	{
234 		try
235 		{
236 			return rb->getString(key);
237 		}
238 		catch (MissingResourceException&)
239 		{
240 			logLS(Level::getError(), LOG4CXX_STR("No resource is associated with key \"") +
241 				key + LOG4CXX_STR("\"."), LocationInfo::getLocationUnavailable());
242 
243 			return LogString();
244 		}
245 	}
246 }
247 
248 
getParent() const249 LoggerPtr Logger::getParent() const
250 {
251 	return parent;
252 }
253 
getLevel() const254 LevelPtr Logger::getLevel() const
255 {
256 	return level;
257 }
258 
259 
isAttached(const AppenderPtr & appender) const260 bool Logger::isAttached(const AppenderPtr& appender) const
261 {
262 	LOCK_R sync(mutex);
263 
264 	if (appender == 0 || aai == 0)
265 	{
266 		return false;
267 	}
268 	else
269 	{
270 		return aai->isAttached(appender);
271 	}
272 }
273 
isTraceEnabled() const274 bool Logger::isTraceEnabled() const
275 {
276 	if (repository == 0 || repository->isDisabled(Level::TRACE_INT))
277 	{
278 		return false;
279 	}
280 
281 	return getEffectiveLevel()->toInt() <= Level::TRACE_INT;
282 }
283 
isDebugEnabled() const284 bool Logger::isDebugEnabled() const
285 {
286 	if (repository == 0 || repository->isDisabled(Level::DEBUG_INT))
287 	{
288 		return false;
289 	}
290 
291 	return getEffectiveLevel()->toInt() <= Level::DEBUG_INT;
292 }
293 
isEnabledFor(const LevelPtr & level1) const294 bool Logger::isEnabledFor(const LevelPtr& level1) const
295 {
296 	if (repository == 0 || repository->isDisabled(level1->toInt()))
297 	{
298 		return false;
299 	}
300 
301 	return level1->isGreaterOrEqual(getEffectiveLevel());
302 }
303 
304 
isInfoEnabled() const305 bool Logger::isInfoEnabled() const
306 {
307 	if (repository == 0 || repository->isDisabled(Level::INFO_INT))
308 	{
309 		return false;
310 	}
311 
312 	return getEffectiveLevel()->toInt() <= Level::INFO_INT;
313 }
314 
isErrorEnabled() const315 bool Logger::isErrorEnabled() const
316 {
317 	if (repository == 0 || repository->isDisabled(Level::ERROR_INT))
318 	{
319 		return false;
320 	}
321 
322 	return getEffectiveLevel()->toInt() <= Level::ERROR_INT;
323 }
324 
isWarnEnabled() const325 bool Logger::isWarnEnabled() const
326 {
327 	if (repository == 0 || repository->isDisabled(Level::WARN_INT))
328 	{
329 		return false;
330 	}
331 
332 	return getEffectiveLevel()->toInt() <= Level::WARN_INT;
333 }
334 
isFatalEnabled() const335 bool Logger::isFatalEnabled() const
336 {
337 	if (repository == 0 || repository->isDisabled(Level::FATAL_INT))
338 	{
339 		return false;
340 	}
341 
342 	return getEffectiveLevel()->toInt() <= Level::FATAL_INT;
343 }
344 
345 /*void Logger::l7dlog(const LevelPtr& level, const String& key,
346                         const char* file, int line)
347 {
348         if (repository == 0 || repository->isDisabled(level->level))
349         {
350                 return;
351         }
352 
353         if (level->isGreaterOrEqual(getEffectiveLevel()))
354         {
355                 String msg = getResourceBundleString(key);
356 
357                 // if message corresponding to 'key' could not be found in the
358                 // resource bundle, then default to 'key'.
359                 if (msg.empty())
360                 {
361                         msg = key;
362                 }
363 
364                 forcedLog(FQCN, level, msg, file, line);
365         }
366 }*/
367 
368 
369 
l7dlog(const LevelPtr & level1,const LogString & key,const LocationInfo & location,const std::vector<LogString> & params) const370 void Logger::l7dlog(const LevelPtr& level1, const LogString& key,
371 	const LocationInfo& location, const std::vector<LogString>& params) const
372 {
373 	if (repository == 0 || repository->isDisabled(level1->toInt()))
374 	{
375 		return;
376 	}
377 
378 	if (level1->isGreaterOrEqual(getEffectiveLevel()))
379 	{
380 		LogString pattern = getResourceBundleString(key);
381 		LogString msg;
382 
383 		if (pattern.empty())
384 		{
385 			msg = key;
386 		}
387 		else
388 		{
389 			msg = StringHelper::format(pattern, params);
390 		}
391 
392 		forcedLogLS(level1, msg, location);
393 	}
394 }
395 
l7dlog(const LevelPtr & level1,const std::string & key,const LocationInfo & location) const396 void Logger::l7dlog(const LevelPtr& level1, const std::string& key,
397 	const LocationInfo& location) const
398 {
399 	LOG4CXX_DECODE_CHAR(lkey, key);
400 
401 	std::vector<LogString> values(0);
402 	l7dlog(level1, lkey, location, values);
403 }
404 
l7dlog(const LevelPtr & level1,const std::string & key,const LocationInfo & location,const std::string & val1) const405 void Logger::l7dlog(const LevelPtr& level1, const std::string& key,
406 	const LocationInfo& location, const std::string& val1) const
407 {
408 	LOG4CXX_DECODE_CHAR(lkey, key);
409 	LOG4CXX_DECODE_CHAR(lval1, val1);
410 
411 	std::vector<LogString> values(1);
412 	values[0] = lval1;
413 	l7dlog(level1, lkey, location, values);
414 }
415 
l7dlog(const LevelPtr & level1,const std::string & key,const LocationInfo & location,const std::string & val1,const std::string & val2) const416 void Logger::l7dlog(const LevelPtr& level1, const std::string& key,
417 	const LocationInfo& location,
418 	const std::string& val1, const std::string& val2) const
419 {
420 	LOG4CXX_DECODE_CHAR(lkey, key);
421 	LOG4CXX_DECODE_CHAR(lval1, val1);
422 	LOG4CXX_DECODE_CHAR(lval2, val2);
423 
424 	std::vector<LogString> values(2);
425 	values[0] = lval1;
426 	values[1] = lval2;
427 	l7dlog(level1, lkey, location, values);
428 }
429 
l7dlog(const LevelPtr & level1,const std::string & key,const LocationInfo & location,const std::string & val1,const std::string & val2,const std::string & val3) const430 void Logger::l7dlog(const LevelPtr& level1, const std::string& key,
431 	const LocationInfo& location,
432 	const std::string& val1, const std::string& val2, const std::string& val3) const
433 {
434 	LOG4CXX_DECODE_CHAR(lkey, key);
435 	LOG4CXX_DECODE_CHAR(lval1, val1);
436 	LOG4CXX_DECODE_CHAR(lval2, val2);
437 	LOG4CXX_DECODE_CHAR(lval3, val3);
438 
439 	std::vector<LogString> values(3);
440 	values[0] = lval1;
441 	values[1] = lval2;
442 	values[2] = lval3;
443 	l7dlog(level1, lkey, location, values);
444 }
445 
446 
447 
removeAllAppenders()448 void Logger::removeAllAppenders()
449 {
450 	LOCK_W sync(mutex);
451 
452 	if (aai != 0)
453 	{
454 		aai->removeAllAppenders();
455 		aai = 0;
456 	}
457 }
458 
removeAppender(const AppenderPtr & appender)459 void Logger::removeAppender(const AppenderPtr& appender)
460 {
461 	LOCK_W sync(mutex);
462 
463 	if (appender == 0 || aai == 0)
464 	{
465 		return;
466 	}
467 
468 	aai->removeAppender(appender);
469 }
470 
removeAppender(const LogString & name1)471 void Logger::removeAppender(const LogString& name1)
472 {
473 	LOCK_W sync(mutex);
474 
475 	if (name1.empty() || aai == 0)
476 	{
477 		return;
478 	}
479 
480 	aai->removeAppender(name1);
481 }
482 
setAdditivity(bool additive1)483 void Logger::setAdditivity(bool additive1)
484 {
485 	LOCK_W sync(mutex);
486 	this->additive = additive1;
487 }
488 
setHierarchy(spi::LoggerRepository * repository1)489 void Logger::setHierarchy(spi::LoggerRepository* repository1)
490 {
491 	this->repository = repository1;
492 }
493 
setLevel(const LevelPtr & level1)494 void Logger::setLevel(const LevelPtr& level1)
495 {
496 	this->level = level1;
497 }
498 
499 
500 
getLogger(const std::string & name)501 LoggerPtr Logger::getLogger(const std::string& name)
502 {
503 	return LogManager::getLogger(name);
504 }
505 
506 
getLogger(const char * const name)507 LoggerPtr Logger::getLogger(const char* const name)
508 {
509 	return LogManager::getLogger(name);
510 }
511 
512 
513 
getRootLogger()514 LoggerPtr Logger::getRootLogger()
515 {
516 	return LogManager::getRootLogger();
517 }
518 
getLoggerLS(const LogString & name,const spi::LoggerFactoryPtr & factory)519 LoggerPtr Logger::getLoggerLS(const LogString& name,
520 	const spi::LoggerFactoryPtr& factory)
521 {
522 	return LogManager::getLoggerLS(name, factory);
523 }
524 
getName(std::string & rv) const525 void Logger::getName(std::string& rv) const
526 {
527 	Transcoder::encode(name, rv);
528 }
529 
530 
trace(const std::string & msg,const log4cxx::spi::LocationInfo & location) const531 void Logger::trace(const std::string& msg, const log4cxx::spi::LocationInfo& location) const
532 {
533 	if (isTraceEnabled())
534 	{
535 		forcedLog(log4cxx::Level::getTrace(), msg, location);
536 	}
537 }
538 
539 
trace(const std::string & msg) const540 void Logger::trace(const std::string& msg) const
541 {
542 	if (isTraceEnabled())
543 	{
544 		forcedLog(log4cxx::Level::getTrace(), msg);
545 	}
546 }
547 
debug(const std::string & msg,const log4cxx::spi::LocationInfo & location) const548 void Logger::debug(const std::string& msg, const log4cxx::spi::LocationInfo& location) const
549 {
550 	if (isDebugEnabled())
551 	{
552 		forcedLog(log4cxx::Level::getDebug(), msg, location);
553 	}
554 }
555 
debug(const std::string & msg) const556 void Logger::debug(const std::string& msg) const
557 {
558 	if (isDebugEnabled())
559 	{
560 		forcedLog(log4cxx::Level::getDebug(), msg);
561 	}
562 }
563 
564 
error(const std::string & msg,const log4cxx::spi::LocationInfo & location) const565 void Logger::error(const std::string& msg, const log4cxx::spi::LocationInfo& location) const
566 {
567 	if (isErrorEnabled())
568 	{
569 		forcedLog(log4cxx::Level::getError(), msg, location);
570 	}
571 }
572 
573 
error(const std::string & msg) const574 void Logger::error(const std::string& msg) const
575 {
576 	if (isErrorEnabled())
577 	{
578 		forcedLog(log4cxx::Level::getError(), msg);
579 	}
580 }
581 
fatal(const std::string & msg,const log4cxx::spi::LocationInfo & location) const582 void Logger::fatal(const std::string& msg, const log4cxx::spi::LocationInfo& location) const
583 {
584 	if (isFatalEnabled())
585 	{
586 		forcedLog(log4cxx::Level::getFatal(), msg, location);
587 	}
588 }
589 
fatal(const std::string & msg) const590 void Logger::fatal(const std::string& msg) const
591 {
592 	if (isFatalEnabled())
593 	{
594 		forcedLog(log4cxx::Level::getFatal(), msg);
595 	}
596 }
597 
info(const std::string & msg,const log4cxx::spi::LocationInfo & location) const598 void Logger::info(const std::string& msg, const log4cxx::spi::LocationInfo& location) const
599 {
600 	if (isInfoEnabled())
601 	{
602 		forcedLog(log4cxx::Level::getInfo(), msg, location);
603 	}
604 }
605 
info(const std::string & msg) const606 void Logger::info(const std::string& msg) const
607 {
608 	if (isInfoEnabled())
609 	{
610 		forcedLog(log4cxx::Level::getInfo(), msg);
611 	}
612 }
613 
log(const LevelPtr & level1,const std::string & message,const log4cxx::spi::LocationInfo & location) const614 void Logger::log(const LevelPtr& level1, const std::string& message,
615 	const log4cxx::spi::LocationInfo& location) const
616 {
617 	if (isEnabledFor(level1))
618 	{
619 		forcedLog(level1, message, location);
620 	}
621 }
622 
log(const LevelPtr & level1,const std::string & message) const623 void Logger::log(const LevelPtr& level1, const std::string& message) const
624 {
625 	if (isEnabledFor(level1))
626 	{
627 		forcedLog(level1, message);
628 	}
629 }
630 
logLS(const LevelPtr & level1,const LogString & message,const log4cxx::spi::LocationInfo & location) const631 void Logger::logLS(const LevelPtr& level1, const LogString& message,
632 	const log4cxx::spi::LocationInfo& location) const
633 {
634 	if (isEnabledFor(level1))
635 	{
636 		forcedLogLS(level1, message, location);
637 	}
638 }
639 
warn(const std::string & msg,const log4cxx::spi::LocationInfo & location) const640 void Logger::warn(const std::string& msg, const log4cxx::spi::LocationInfo& location) const
641 {
642 	if (isWarnEnabled())
643 	{
644 		forcedLog(log4cxx::Level::getWarn(), msg, location);
645 	}
646 }
647 
warn(const std::string & msg) const648 void Logger::warn(const std::string& msg) const
649 {
650 	if (isWarnEnabled())
651 	{
652 		forcedLog(log4cxx::Level::getWarn(), msg);
653 	}
654 }
655 
getLoggerLS(const LogString & name)656 LoggerPtr Logger::getLoggerLS(const LogString& name)
657 {
658 	return LogManager::getLoggerLS(name);
659 }
660 
661 
662 
663 
664 #if LOG4CXX_WCHAR_T_API
forcedLog(const LevelPtr & level1,const std::wstring & message,const LocationInfo & location) const665 void Logger::forcedLog(const LevelPtr& level1, const std::wstring& message,
666 	const LocationInfo& location) const
667 {
668 	Pool p;
669 	LOG4CXX_DECODE_WCHAR(msg, message);
670 	LoggingEventPtr event(new LoggingEvent(name, level1, msg, location));
671 	callAppenders(event, p);
672 }
673 
forcedLog(const LevelPtr & level1,const std::wstring & message) const674 void Logger::forcedLog(const LevelPtr& level1, const std::wstring& message) const
675 {
676 	Pool p;
677 	LOG4CXX_DECODE_WCHAR(msg, message);
678 	LoggingEventPtr event(new LoggingEvent(name, level1, msg,
679 			LocationInfo::getLocationUnavailable()));
680 	callAppenders(event, p);
681 }
682 
getName(std::wstring & rv) const683 void Logger::getName(std::wstring& rv) const
684 {
685 	Transcoder::encode(name, rv);
686 }
687 
getLogger(const std::wstring & name)688 LoggerPtr Logger::getLogger(const std::wstring& name)
689 {
690 	return LogManager::getLogger(name);
691 }
692 
getLogger(const wchar_t * const name)693 LoggerPtr Logger::getLogger(const wchar_t* const name)
694 {
695 	return LogManager::getLogger(name);
696 }
697 
trace(const std::wstring & msg,const log4cxx::spi::LocationInfo & location) const698 void Logger::trace(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const
699 {
700 	if (isTraceEnabled())
701 	{
702 		forcedLog(log4cxx::Level::getTrace(), msg, location);
703 	}
704 }
705 
706 
trace(const std::wstring & msg) const707 void Logger::trace(const std::wstring& msg) const
708 {
709 	if (isTraceEnabled())
710 	{
711 		forcedLog(log4cxx::Level::getTrace(), msg);
712 	}
713 }
714 
debug(const std::wstring & msg,const log4cxx::spi::LocationInfo & location) const715 void Logger::debug(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const
716 {
717 	if (isDebugEnabled())
718 	{
719 		forcedLog(log4cxx::Level::getDebug(), msg, location);
720 	}
721 }
722 
debug(const std::wstring & msg) const723 void Logger::debug(const std::wstring& msg) const
724 {
725 	if (isDebugEnabled())
726 	{
727 		forcedLog(log4cxx::Level::getDebug(), msg);
728 	}
729 }
730 
error(const std::wstring & msg,const log4cxx::spi::LocationInfo & location) const731 void Logger::error(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const
732 {
733 	if (isErrorEnabled())
734 	{
735 		forcedLog(log4cxx::Level::getError(), msg, location);
736 	}
737 }
738 
error(const std::wstring & msg) const739 void Logger::error(const std::wstring& msg) const
740 {
741 	if (isErrorEnabled())
742 	{
743 		forcedLog(log4cxx::Level::getError(), msg);
744 	}
745 }
746 
fatal(const std::wstring & msg,const log4cxx::spi::LocationInfo & location) const747 void Logger::fatal(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const
748 {
749 	if (isFatalEnabled())
750 	{
751 		forcedLog(log4cxx::Level::getFatal(), msg, location);
752 	}
753 }
754 
fatal(const std::wstring & msg) const755 void Logger::fatal(const std::wstring& msg) const
756 {
757 	if (isFatalEnabled())
758 	{
759 		forcedLog(log4cxx::Level::getFatal(), msg);
760 	}
761 }
762 
info(const std::wstring & msg,const log4cxx::spi::LocationInfo & location) const763 void Logger::info(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const
764 {
765 	if (isInfoEnabled())
766 	{
767 		forcedLog(log4cxx::Level::getInfo(), msg, location);
768 	}
769 }
770 
info(const std::wstring & msg) const771 void Logger::info(const std::wstring& msg) const
772 {
773 	if (isInfoEnabled())
774 	{
775 		forcedLog(log4cxx::Level::getInfo(), msg);
776 	}
777 }
778 
log(const LevelPtr & level1,const std::wstring & message,const log4cxx::spi::LocationInfo & location) const779 void Logger::log(const LevelPtr& level1, const std::wstring& message,
780 	const log4cxx::spi::LocationInfo& location) const
781 {
782 	if (isEnabledFor(level1))
783 	{
784 		forcedLog(level1, message, location);
785 	}
786 }
787 
log(const LevelPtr & level1,const std::wstring & message) const788 void Logger::log(const LevelPtr& level1, const std::wstring& message) const
789 {
790 	if (isEnabledFor(level1))
791 	{
792 		forcedLog(level1, message);
793 	}
794 }
795 
warn(const std::wstring & msg,const log4cxx::spi::LocationInfo & location) const796 void Logger::warn(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const
797 {
798 	if (isWarnEnabled())
799 	{
800 		forcedLog(log4cxx::Level::getWarn(), msg, location);
801 	}
802 }
803 
warn(const std::wstring & msg) const804 void Logger::warn(const std::wstring& msg) const
805 {
806 	if (isWarnEnabled())
807 	{
808 		forcedLog(log4cxx::Level::getWarn(), msg);
809 	}
810 }
811 
812 #endif
813 
814 
815 #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
forcedLog(const LevelPtr & level1,const std::basic_string<UniChar> & message,const LocationInfo & location) const816 void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message,
817 	const LocationInfo& location) const
818 {
819 	Pool p;
820 	LOG4CXX_DECODE_UNICHAR(msg, message);
821 	LoggingEventPtr event(new LoggingEvent(name, level1, msg, location));
822 	callAppenders(event, p);
823 }
824 
forcedLog(const LevelPtr & level1,const std::basic_string<UniChar> & message) const825 void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message) const
826 {
827 	Pool p;
828 	LOG4CXX_DECODE_UNICHAR(msg, message);
829 	LoggingEventPtr event(new LoggingEvent(name, level1, msg,
830 			LocationInfo::getLocationUnavailable()));
831 	callAppenders(event, p);
832 }
833 #endif
834 
835 #if LOG4CXX_UNICHAR_API
getName(std::basic_string<UniChar> & rv) const836 void Logger::getName(std::basic_string<UniChar>& rv) const
837 {
838 	Transcoder::encode(name, rv);
839 }
840 
getLogger(const std::basic_string<UniChar> & name)841 LoggerPtr Logger::getLogger(const std::basic_string<UniChar>& name)
842 {
843 	return LogManager::getLogger(name);
844 }
845 
trace(const std::basic_string<UniChar> & msg,const log4cxx::spi::LocationInfo & location) const846 void Logger::trace(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const
847 {
848 	if (isTraceEnabled())
849 	{
850 		forcedLog(log4cxx::Level::getTrace(), msg, location);
851 	}
852 }
853 
854 
trace(const std::basic_string<UniChar> & msg) const855 void Logger::trace(const std::basic_string<UniChar>& msg) const
856 {
857 	if (isTraceEnabled())
858 	{
859 		forcedLog(log4cxx::Level::getTrace(), msg);
860 	}
861 }
862 
debug(const std::basic_string<UniChar> & msg,const log4cxx::spi::LocationInfo & location) const863 void Logger::debug(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const
864 {
865 	if (isDebugEnabled())
866 	{
867 		forcedLog(log4cxx::Level::getDebug(), msg, location);
868 	}
869 }
870 
debug(const std::basic_string<UniChar> & msg) const871 void Logger::debug(const std::basic_string<UniChar>& msg) const
872 {
873 	if (isDebugEnabled())
874 	{
875 		forcedLog(log4cxx::Level::getDebug(), msg);
876 	}
877 }
878 
error(const std::basic_string<UniChar> & msg,const log4cxx::spi::LocationInfo & location) const879 void Logger::error(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const
880 {
881 	if (isErrorEnabled())
882 	{
883 		forcedLog(log4cxx::Level::getError(), msg, location);
884 	}
885 }
886 
error(const std::basic_string<UniChar> & msg) const887 void Logger::error(const std::basic_string<UniChar>& msg) const
888 {
889 	if (isErrorEnabled())
890 	{
891 		forcedLog(log4cxx::Level::getError(), msg);
892 	}
893 }
894 
fatal(const std::basic_string<UniChar> & msg,const log4cxx::spi::LocationInfo & location) const895 void Logger::fatal(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const
896 {
897 	if (isFatalEnabled())
898 	{
899 		forcedLog(log4cxx::Level::getFatal(), msg, location);
900 	}
901 }
902 
fatal(const std::basic_string<UniChar> & msg) const903 void Logger::fatal(const std::basic_string<UniChar>& msg) const
904 {
905 	if (isFatalEnabled())
906 	{
907 		forcedLog(log4cxx::Level::getFatal(), msg);
908 	}
909 }
910 
info(const std::basic_string<UniChar> & msg,const log4cxx::spi::LocationInfo & location) const911 void Logger::info(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const
912 {
913 	if (isInfoEnabled())
914 	{
915 		forcedLog(log4cxx::Level::getInfo(), msg, location);
916 	}
917 }
918 
info(const std::basic_string<UniChar> & msg) const919 void Logger::info(const std::basic_string<UniChar>& msg) const
920 {
921 	if (isInfoEnabled())
922 	{
923 		forcedLog(log4cxx::Level::getInfo(), msg);
924 	}
925 }
926 
log(const LevelPtr & level1,const std::basic_string<UniChar> & message,const log4cxx::spi::LocationInfo & location) const927 void Logger::log(const LevelPtr& level1, const std::basic_string<UniChar>& message,
928 	const log4cxx::spi::LocationInfo& location) const
929 {
930 	if (isEnabledFor(level1))
931 	{
932 		forcedLog(level1, message, location);
933 	}
934 }
935 
log(const LevelPtr & level1,const std::basic_string<UniChar> & message) const936 void Logger::log(const LevelPtr& level1, const std::basic_string<UniChar>& message) const
937 {
938 	if (isEnabledFor(level1))
939 	{
940 		forcedLog(level1, message);
941 	}
942 }
943 
warn(const std::basic_string<UniChar> & msg,const log4cxx::spi::LocationInfo & location) const944 void Logger::warn(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const
945 {
946 	if (isWarnEnabled())
947 	{
948 		forcedLog(log4cxx::Level::getWarn(), msg, location);
949 	}
950 }
951 
warn(const std::basic_string<UniChar> & msg) const952 void Logger::warn(const std::basic_string<UniChar>& msg) const
953 {
954 	if (isWarnEnabled())
955 	{
956 		forcedLog(log4cxx::Level::getWarn(), msg);
957 	}
958 }
959 
960 #endif
961 
962 
963 #if LOG4CXX_CFSTRING_API
forcedLog(const LevelPtr & level1,const CFStringRef & message,const LocationInfo & location) const964 void Logger::forcedLog(const LevelPtr& level1, const CFStringRef& message,
965 	const LocationInfo& location) const
966 {
967 	Pool p;
968 	LOG4CXX_DECODE_CFSTRING(msg, message);
969 	LoggingEventPtr event(new LoggingEvent(name, level1, msg, location));
970 	callAppenders(event, p);
971 }
972 
forcedLog(const LevelPtr & level1,const CFStringRef & message) const973 void Logger::forcedLog(const LevelPtr& level1, const CFStringRef& message) const
974 {
975 	Pool p;
976 	LOG4CXX_DECODE_CFSTRING(msg, message);
977 	LoggingEventPtr event(new LoggingEvent(name, level1, msg,
978 			LocationInfo::getLocationUnavailable()));
979 	callAppenders(event, p);
980 }
981 
getName(CFStringRef & rv) const982 void Logger::getName(CFStringRef& rv) const
983 {
984 	rv = Transcoder::encode(name);
985 }
986 
getLogger(const CFStringRef & name)987 LoggerPtr Logger::getLogger(const CFStringRef& name)
988 {
989 	return LogManager::getLogger(name);
990 }
991 
trace(const CFStringRef & msg,const log4cxx::spi::LocationInfo & location) const992 void Logger::trace(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const
993 {
994 	if (isTraceEnabled())
995 	{
996 		forcedLog(log4cxx::Level::getTrace(), msg, location);
997 	}
998 }
999 
1000 
trace(const CFStringRef & msg) const1001 void Logger::trace(const CFStringRef& msg) const
1002 {
1003 	if (isTraceEnabled())
1004 	{
1005 		forcedLog(log4cxx::Level::getTrace(), msg);
1006 	}
1007 }
1008 
debug(const CFStringRef & msg,const log4cxx::spi::LocationInfo & location) const1009 void Logger::debug(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const
1010 {
1011 	if (isDebugEnabled())
1012 	{
1013 		forcedLog(log4cxx::Level::getDebug(), msg, location);
1014 	}
1015 }
1016 
debug(const CFStringRef & msg) const1017 void Logger::debug(const CFStringRef& msg) const
1018 {
1019 	if (isDebugEnabled())
1020 	{
1021 		forcedLog(log4cxx::Level::getDebug(), msg);
1022 	}
1023 }
1024 
error(const CFStringRef & msg,const log4cxx::spi::LocationInfo & location) const1025 void Logger::error(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const
1026 {
1027 	if (isErrorEnabled())
1028 	{
1029 		forcedLog(log4cxx::Level::getError(), msg, location);
1030 	}
1031 }
1032 
error(const CFStringRef & msg) const1033 void Logger::error(const CFStringRef& msg) const
1034 {
1035 	if (isErrorEnabled())
1036 	{
1037 		forcedLog(log4cxx::Level::getError(), msg);
1038 	}
1039 }
1040 
fatal(const CFStringRef & msg,const log4cxx::spi::LocationInfo & location) const1041 void Logger::fatal(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const
1042 {
1043 	if (isFatalEnabled())
1044 	{
1045 		forcedLog(log4cxx::Level::getFatal(), msg, location);
1046 	}
1047 }
1048 
fatal(const CFStringRef & msg) const1049 void Logger::fatal(const CFStringRef& msg) const
1050 {
1051 	if (isFatalEnabled())
1052 	{
1053 		forcedLog(log4cxx::Level::getFatal(), msg);
1054 	}
1055 }
1056 
info(const CFStringRef & msg,const log4cxx::spi::LocationInfo & location) const1057 void Logger::info(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const
1058 {
1059 	if (isInfoEnabled())
1060 	{
1061 		forcedLog(log4cxx::Level::getInfo(), msg, location);
1062 	}
1063 }
1064 
info(const CFStringRef & msg) const1065 void Logger::info(const CFStringRef& msg) const
1066 {
1067 	if (isInfoEnabled())
1068 	{
1069 		forcedLog(log4cxx::Level::getInfo(), msg);
1070 	}
1071 }
1072 
log(const LevelPtr & level1,const CFStringRef & message,const log4cxx::spi::LocationInfo & location) const1073 void Logger::log(const LevelPtr& level1, const CFStringRef& message,
1074 	const log4cxx::spi::LocationInfo& location) const
1075 {
1076 	if (isEnabledFor(level1))
1077 	{
1078 		forcedLog(level1, message, location);
1079 	}
1080 }
1081 
log(const LevelPtr & level1,const CFStringRef & message) const1082 void Logger::log(const LevelPtr& level1, const CFStringRef& message) const
1083 {
1084 	if (isEnabledFor(level1))
1085 	{
1086 		forcedLog(level1, message);
1087 	}
1088 }
1089 
warn(const CFStringRef & msg,const log4cxx::spi::LocationInfo & location) const1090 void Logger::warn(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const
1091 {
1092 	if (isWarnEnabled())
1093 	{
1094 		forcedLog(log4cxx::Level::getWarn(), msg, location);
1095 	}
1096 }
1097 
warn(const CFStringRef & msg) const1098 void Logger::warn(const CFStringRef& msg) const
1099 {
1100 	if (isWarnEnabled())
1101 	{
1102 		forcedLog(log4cxx::Level::getWarn(), msg);
1103 	}
1104 }
1105 
1106 #endif
1107 
1108 
1109