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 #ifndef _LOG4CXX_LOGGER_H 19 #define _LOG4CXX_LOGGER_H 20 21 #if defined(_MSC_VER) && (_MSC_VER < 1900) 22 #pragma warning ( push ) 23 #pragma warning ( disable: 4127 ) 24 #endif 25 #if defined(_MSC_VER) 26 #pragma warning ( push ) 27 #pragma warning ( disable: 4231 4251 4275 4786 ) 28 #endif 29 30 #include <log4cxx/helpers/appenderattachableimpl.h> 31 #include <log4cxx/level.h> 32 #include <log4cxx/helpers/pool.h> 33 #include <log4cxx/helpers/mutex.h> 34 #include <log4cxx/spi/location/locationinfo.h> 35 #include <log4cxx/helpers/resourcebundle.h> 36 #include <log4cxx/helpers/messagebuffer.h> 37 38 39 namespace log4cxx 40 { 41 42 namespace helpers 43 { 44 class synchronized; 45 } 46 47 namespace spi 48 { 49 class LoggerRepository; 50 LOG4CXX_PTR_DEF(LoggerRepository); 51 class LoggerFactory; 52 LOG4CXX_PTR_DEF(LoggerFactory); 53 } 54 55 class Logger; 56 /** smart pointer to a Logger class */ 57 LOG4CXX_PTR_DEF(Logger); 58 LOG4CXX_LIST_DEF(LoggerList, LoggerPtr); 59 60 61 /** 62 This is the central class in the log4cxx package. Most logging 63 operations, except configuration, are done through this class. 64 */ 65 class LOG4CXX_EXPORT Logger : 66 public virtual log4cxx::spi::AppenderAttachable, 67 public virtual helpers::ObjectImpl 68 { 69 public: 70 DECLARE_ABSTRACT_LOG4CXX_OBJECT(Logger) 71 BEGIN_LOG4CXX_CAST_MAP() 72 LOG4CXX_CAST_ENTRY(Logger) 73 LOG4CXX_CAST_ENTRY(spi::AppenderAttachable) 74 END_LOG4CXX_CAST_MAP() 75 76 private: 77 /** 78 * Reference to memory pool. 79 */ 80 helpers::Pool* pool; 81 82 protected: 83 /** 84 The name of this logger. 85 */ 86 LogString name; 87 88 /** 89 The assigned level of this logger. The 90 <code>level</code> variable need not be assigned a value in 91 which case it is inherited form the hierarchy. */ 92 LevelPtr level; 93 94 /** 95 The parent of this logger. All loggers have at least one 96 ancestor which is the root logger. */ 97 LoggerPtr parent; 98 99 /** The resourceBundle for localized messages. 100 101 @see setResourceBundle, getResourceBundle 102 */ 103 helpers::ResourceBundlePtr resourceBundle; 104 105 106 // Loggers need to know what Hierarchy they are in 107 log4cxx::spi::LoggerRepository* repository; 108 109 helpers::AppenderAttachableImplPtr aai; 110 111 /** Additivity is set to true by default, that is children inherit 112 the appenders of their ancestors by default. If this variable is 113 set to <code>false</code> then the appenders found in the 114 ancestors of this logger are not used. However, the children 115 of this logger will inherit its appenders, unless the children 116 have their additivity flag set to <code>false</code> too. See 117 the user manual for more details. */ 118 bool additive; 119 120 protected: 121 friend class DefaultLoggerFactory; 122 123 /** 124 This constructor created a new <code>logger</code> instance and 125 sets its name. 126 127 <p>It is intended to be used by sub-classes only. You should not 128 create categories directly. 129 130 @param pool lifetime of pool must be longer than logger. 131 @param name The name of the logger. 132 */ 133 Logger(log4cxx::helpers::Pool& pool, const LogString& name); 134 135 public: 136 ~Logger(); 137 138 139 void addRef() const; 140 void releaseRef() const; 141 142 /** 143 Add <code>newAppender</code> to the list of appenders of this 144 Logger instance. 145 146 <p>If <code>newAppender</code> is already in the list of 147 appenders, then it won't be added again. 148 */ 149 virtual void addAppender(const AppenderPtr& newAppender); 150 151 152 /** 153 Call the appenders in the hierrachy starting at 154 <code>this</code>. If no appenders could be found, emit a 155 warning. 156 157 <p>This method calls all the appenders inherited from the 158 hierarchy circumventing any evaluation of whether to log or not 159 to log the particular log request. 160 161 @param event the event to log. 162 @param p memory pool for any allocations needed to process request. 163 */ 164 void callAppenders(const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) const; 165 166 /** 167 Close all attached appenders implementing the AppenderAttachable 168 interface. 169 */ 170 void closeNestedAppenders(); 171 172 /** 173 Log a message string with the DEBUG level. 174 175 <p>This method first checks if this logger is <code>DEBUG</code> 176 enabled by comparing the level of this logger with the 177 DEBUG level. If this logger is 178 <code>DEBUG</code> enabled, it proceeds to call all the 179 registered appenders in this logger and also higher in the 180 hierarchy depending on the value of the additivity flag. 181 182 @param msg the message string to log. 183 @param location location of source of logging request. 184 */ 185 void debug(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; 186 /** 187 Log a message string with the DEBUG level. 188 189 <p>This method first checks if this logger is <code>DEBUG</code> 190 enabled by comparing the level of this logger with the 191 DEBUG level. If this logger is 192 <code>DEBUG</code> enabled, it proceeds to call all the 193 registered appenders in this logger and also higher in the 194 hierarchy depending on the value of the additivity flag. 195 196 @param msg the message string to log. 197 */ 198 void debug(const std::string& msg) const; 199 #if LOG4CXX_WCHAR_T_API 200 /** 201 Log a message string with the DEBUG level. 202 203 <p>This method first checks if this logger is <code>DEBUG</code> 204 enabled by comparing the level of this logger with the 205 DEBUG level. If this logger is 206 <code>DEBUG</code> enabled, it proceeds to call all the 207 registered appenders in this logger and also higher in the 208 hierarchy depending on the value of the additivity flag. 209 210 @param msg the message string to log. 211 @param location location of source of logging request. 212 */ 213 void debug(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; 214 /** 215 Log a message string with the DEBUG level. 216 217 <p>This method first checks if this logger is <code>DEBUG</code> 218 enabled by comparing the level of this logger with the 219 DEBUG level. If this logger is 220 <code>DEBUG</code> enabled, it proceeds to call all the 221 registered appenders in this logger and also higher in the 222 hierarchy depending on the value of the additivity flag. 223 224 @param msg the message string to log. 225 */ 226 void debug(const std::wstring& msg) const; 227 #endif 228 #if LOG4CXX_UNICHAR_API 229 /** 230 Log a message string with the DEBUG level. 231 232 <p>This method first checks if this logger is <code>DEBUG</code> 233 enabled by comparing the level of this logger with the 234 DEBUG level. If this logger is 235 <code>DEBUG</code> enabled, it proceeds to call all the 236 registered appenders in this logger and also higher in the 237 hierarchy depending on the value of the additivity flag. 238 239 @param msg the message string to log. 240 @param location location of source of logging request. 241 */ 242 void debug(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; 243 /** 244 Log a message string with the DEBUG level. 245 246 <p>This method first checks if this logger is <code>DEBUG</code> 247 enabled by comparing the level of this logger with the 248 DEBUG level. If this logger is 249 <code>DEBUG</code> enabled, it proceeds to call all the 250 registered appenders in this logger and also higher in the 251 hierarchy depending on the value of the additivity flag. 252 253 @param msg the message string to log. 254 */ 255 void debug(const std::basic_string<UniChar>& msg) const; 256 #endif 257 #if LOG4CXX_CFSTRING_API 258 /** 259 Log a message string with the DEBUG level. 260 261 <p>This method first checks if this logger is <code>DEBUG</code> 262 enabled by comparing the level of this logger with the 263 DEBUG level. If this logger is 264 <code>DEBUG</code> enabled, it proceeds to call all the 265 registered appenders in this logger and also higher in the 266 hierarchy depending on the value of the additivity flag. 267 268 @param msg the message string to log. 269 @param location location of source of logging request. 270 */ 271 void debug(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; 272 /** 273 Log a message string with the DEBUG level. 274 275 <p>This method first checks if this logger is <code>DEBUG</code> 276 enabled by comparing the level of this logger with the 277 DEBUG level. If this logger is 278 <code>DEBUG</code> enabled, it proceeds to call all the 279 registered appenders in this logger and also higher in the 280 hierarchy depending on the value of the additivity flag. 281 282 @param msg the message string to log. 283 */ 284 void debug(const CFStringRef& msg) const; 285 #endif 286 287 /** 288 Log a message string with the ERROR level. 289 290 <p>This method first checks if this logger is <code>ERROR</code> 291 enabled by comparing the level of this logger with the 292 ERROR level. If this logger is 293 <code>ERROR</code> enabled, it proceeds to call all the 294 registered appenders in this logger and also higher in the 295 hierarchy depending on the value of the additivity flag. 296 297 @param msg the message string to log. 298 @param location location of source of logging request. 299 */ 300 void error(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; 301 /** 302 Log a message string with the ERROR level. 303 304 <p>This method first checks if this logger is <code>ERROR</code> 305 enabled by comparing the level of this logger with the 306 ERROR level. If this logger is 307 <code>ERROR</code> enabled, it proceeds to call all the 308 registered appenders in this logger and also higher in the 309 hierarchy depending on the value of the additivity flag. 310 311 @param msg the message string to log. 312 */ 313 void error(const std::string& msg) const; 314 #if LOG4CXX_WCHAR_T_API 315 /** 316 Log a message string with the ERROR level. 317 318 <p>This method first checks if this logger is <code>ERROR</code> 319 enabled by comparing the level of this logger with the 320 ERROR level. If this logger is 321 <code>ERROR</code> enabled, it proceeds to call all the 322 registered appenders in this logger and also higher in the 323 hierarchy depending on the value of the additivity flag. 324 325 @param msg the message string to log. 326 */ 327 void error(const std::wstring& msg) const; 328 /** 329 Log a message string with the ERROR level. 330 331 <p>This method first checks if this logger is <code>ERROR</code> 332 enabled by comparing the level of this logger with the 333 ERROR level. If this logger is 334 <code>ERROR</code> enabled, it proceeds to call all the 335 registered appenders in this logger and also higher in the 336 hierarchy depending on the value of the additivity flag. 337 338 @param msg the message string to log. 339 @param location location of source of logging request. 340 */ 341 void error(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; 342 #endif 343 #if LOG4CXX_UNICHAR_API 344 /** 345 Log a message string with the ERROR level. 346 347 <p>This method first checks if this logger is <code>ERROR</code> 348 enabled by comparing the level of this logger with the 349 ERROR level. If this logger is 350 <code>ERROR</code> enabled, it proceeds to call all the 351 registered appenders in this logger and also higher in the 352 hierarchy depending on the value of the additivity flag. 353 354 @param msg the message string to log. 355 @param location location of source of logging request. 356 */ 357 void error(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; 358 /** 359 Log a message string with the ERROR level. 360 361 <p>This method first checks if this logger is <code>ERROR</code> 362 enabled by comparing the level of this logger with the 363 ERROR level. If this logger is 364 <code>ERROR</code> enabled, it proceeds to call all the 365 registered appenders in this logger and also higher in the 366 hierarchy depending on the value of the additivity flag. 367 368 @param msg the message string to log. 369 */ 370 void error(const std::basic_string<UniChar>& msg) const; 371 #endif 372 #if LOG4CXX_CFSTRING_API 373 /** 374 Log a message string with the ERROR level. 375 376 <p>This method first checks if this logger is <code>ERROR</code> 377 enabled by comparing the level of this logger with the 378 ERROR level. If this logger is 379 <code>ERROR</code> enabled, it proceeds to call all the 380 registered appenders in this logger and also higher in the 381 hierarchy depending on the value of the additivity flag. 382 383 @param msg the message string to log. 384 @param location location of source of logging request. 385 */ 386 void error(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; 387 /** 388 Log a message string with the ERROR level. 389 390 <p>This method first checks if this logger is <code>ERROR</code> 391 enabled by comparing the level of this logger with the 392 ERROR level. If this logger is 393 <code>ERROR</code> enabled, it proceeds to call all the 394 registered appenders in this logger and also higher in the 395 hierarchy depending on the value of the additivity flag. 396 397 @param msg the message string to log. 398 */ 399 void error(const CFStringRef& msg) const; 400 #endif 401 402 /** 403 Log a message string with the FATAL level. 404 405 <p>This method first checks if this logger is <code>FATAL</code> 406 enabled by comparing the level of this logger with the 407 FATAL level. If this logger is 408 <code>FATAL</code> enabled, it proceeds to call all the 409 registered appenders in this logger and also higher in the 410 hierarchy depending on the value of the additivity flag. 411 412 @param msg the message string to log. 413 @param location location of source of logging request. 414 */ 415 void fatal(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; 416 /** 417 Log a message string with the ERROR level. 418 419 <p>This method first checks if this logger is <code>ERROR</code> 420 enabled by comparing the level of this logger with the 421 ERROR level. If this logger is 422 <code>ERROR</code> enabled, it proceeds to call all the 423 registered appenders in this logger and also higher in the 424 hierarchy depending on the value of the additivity flag. 425 426 @param msg the message string to log. 427 */ 428 void fatal(const std::string& msg) const; 429 #if LOG4CXX_WCHAR_T_API 430 /** 431 Log a message string with the ERROR level. 432 433 <p>This method first checks if this logger is <code>ERROR</code> 434 enabled by comparing the level of this logger with the 435 ERROR level. If this logger is 436 <code>ERROR</code> enabled, it proceeds to call all the 437 registered appenders in this logger and also higher in the 438 hierarchy depending on the value of the additivity flag. 439 440 @param msg the message string to log. 441 @param location location of source of logging request. 442 */ 443 void fatal(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; 444 /** 445 Log a message string with the ERROR level. 446 447 <p>This method first checks if this logger is <code>ERROR</code> 448 enabled by comparing the level of this logger with the 449 ERROR level. If this logger is 450 <code>ERROR</code> enabled, it proceeds to call all the 451 registered appenders in this logger and also higher in the 452 hierarchy depending on the value of the additivity flag. 453 454 @param msg the message string to log. 455 */ 456 void fatal(const std::wstring& msg) const; 457 #endif 458 #if LOG4CXX_UNICHAR_API 459 /** 460 Log a message string with the ERROR level. 461 462 <p>This method first checks if this logger is <code>ERROR</code> 463 enabled by comparing the level of this logger with the 464 ERROR level. If this logger is 465 <code>ERROR</code> enabled, it proceeds to call all the 466 registered appenders in this logger and also higher in the 467 hierarchy depending on the value of the additivity flag. 468 469 @param msg the message string to log. 470 @param location location of source of logging request. 471 */ 472 void fatal(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; 473 /** 474 Log a message string with the ERROR level. 475 476 <p>This method first checks if this logger is <code>ERROR</code> 477 enabled by comparing the level of this logger with the 478 ERROR level. If this logger is 479 <code>ERROR</code> enabled, it proceeds to call all the 480 registered appenders in this logger and also higher in the 481 hierarchy depending on the value of the additivity flag. 482 483 @param msg the message string to log. 484 */ 485 void fatal(const std::basic_string<UniChar>& msg) const; 486 #endif 487 #if LOG4CXX_CFSTRING_API 488 /** 489 Log a message string with the ERROR level. 490 491 <p>This method first checks if this logger is <code>ERROR</code> 492 enabled by comparing the level of this logger with the 493 ERROR level. If this logger is 494 <code>ERROR</code> enabled, it proceeds to call all the 495 registered appenders in this logger and also higher in the 496 hierarchy depending on the value of the additivity flag. 497 498 @param msg the message string to log. 499 @param location location of source of logging request. 500 */ 501 void fatal(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; 502 /** 503 Log a message string with the ERROR level. 504 505 <p>This method first checks if this logger is <code>ERROR</code> 506 enabled by comparing the level of this logger with the 507 ERROR level. If this logger is 508 <code>ERROR</code> enabled, it proceeds to call all the 509 registered appenders in this logger and also higher in the 510 hierarchy depending on the value of the additivity flag. 511 512 @param msg the message string to log. 513 */ 514 void fatal(const CFStringRef& msg) const; 515 #endif 516 517 /** 518 This method creates a new logging event and logs the event 519 without further checks. 520 @param level the level to log. 521 @param message message. 522 @param location location of source of logging request. 523 */ 524 void forcedLog(const LevelPtr& level, const std::string& message, 525 const log4cxx::spi::LocationInfo& location) const; 526 /** 527 This method creates a new logging event and logs the event 528 without further checks. 529 @param level the level to log. 530 @param message message. 531 */ 532 void forcedLog(const LevelPtr& level, const std::string& message) const; 533 534 #if LOG4CXX_WCHAR_T_API 535 /** 536 This method creates a new logging event and logs the event 537 without further checks. 538 @param level the level to log. 539 @param message message. 540 @param location location of source of logging request. 541 */ 542 void forcedLog(const LevelPtr& level, const std::wstring& message, 543 const log4cxx::spi::LocationInfo& location) const; 544 /** 545 This method creates a new logging event and logs the event 546 without further checks. 547 @param level the level to log. 548 @param message message. 549 */ 550 void forcedLog(const LevelPtr& level, const std::wstring& message) const; 551 #endif 552 #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API 553 /** 554 This method creates a new logging event and logs the event 555 without further checks. 556 @param level the level to log. 557 @param message message. 558 @param location location of source of logging request. 559 */ 560 void forcedLog(const LevelPtr& level, const std::basic_string<UniChar>& message, 561 const log4cxx::spi::LocationInfo& location) const; 562 /** 563 This method creates a new logging event and logs the event 564 without further checks. 565 @param level the level to log. 566 @param message message. 567 */ 568 void forcedLog(const LevelPtr& level, const std::basic_string<UniChar>& message) const; 569 #endif 570 #if LOG4CXX_CFSTRING_API 571 /** 572 This method creates a new logging event and logs the event 573 without further checks. 574 @param level the level to log. 575 @param message message. 576 @param location location of source of logging request. 577 */ 578 void forcedLog(const LevelPtr& level, const CFStringRef& message, 579 const log4cxx::spi::LocationInfo& location) const; 580 /** 581 This method creates a new logging event and logs the event 582 without further checks. 583 @param level the level to log. 584 @param message message. 585 */ 586 void forcedLog(const LevelPtr& level, const CFStringRef& message) const; 587 #endif 588 /** 589 This method creates a new logging event and logs the event 590 without further checks. 591 @param level the level to log. 592 @param message the message string to log. 593 @param location location of the logging statement. 594 */ 595 void forcedLogLS(const LevelPtr& level, const LogString& message, 596 const log4cxx::spi::LocationInfo& location) const; 597 598 /** 599 Get the additivity flag for this Logger instance. 600 */ 601 bool getAdditivity() const; 602 603 /** 604 Get the appenders contained in this logger as an AppenderList. 605 If no appenders can be found, then an empty AppenderList 606 is returned. 607 @return AppenderList An collection of the appenders in this logger.*/ 608 AppenderList getAllAppenders() const; 609 610 /** 611 Look for the appender named as <code>name</code>. 612 <p>Return the appender with that name if in the list. Return 613 <code>NULL</code> otherwise. */ 614 AppenderPtr getAppender(const LogString& name) const; 615 616 /** 617 Starting from this logger, search the logger hierarchy for a 618 non-null level and return it. 619 620 <p>The Logger class is designed so that this method executes as 621 quickly as possible. 622 623 @throws RuntimeException if all levels are null in the hierarchy 624 */ 625 virtual const LevelPtr& getEffectiveLevel() const; 626 627 /** 628 Return the the LoggerRepository where this 629 <code>Logger</code> is attached. 630 */ 631 log4cxx::spi::LoggerRepositoryPtr getLoggerRepository() const; 632 633 634 /** 635 * Get the logger name. 636 * @return logger name as LogString. 637 */ getName()638 const LogString& getName() const 639 { 640 return name; 641 } 642 /** 643 * Get logger name in current encoding. 644 * @param name buffer to which name is appended. 645 */ 646 void getName(std::string& name) const; 647 #if LOG4CXX_WCHAR_T_API 648 /** 649 * Get logger name. 650 * @param name buffer to which name is appended. 651 */ 652 void getName(std::wstring& name) const; 653 #endif 654 #if LOG4CXX_UNICHAR_API 655 /** 656 * Get logger name. 657 * @param name buffer to which name is appended. 658 */ 659 void getName(std::basic_string<UniChar>& name) const; 660 #endif 661 #if LOG4CXX_CFSTRING_API 662 /** 663 * Get logger name. 664 * @param name buffer to which name is appended. 665 */ 666 void getName(CFStringRef& name) const; 667 #endif 668 669 /** 670 Returns the parent of this logger. Note that the parent of a 671 given logger may change during the lifetime of the logger. 672 673 <p>The root logger will return <code>0</code>. 674 */ 675 LoggerPtr getParent() const; 676 677 678 /** 679 Returns the assigned Level, if any, for this Logger. 680 681 @return Level - the assigned Level, can be null. 682 */ 683 LevelPtr getLevel() const; 684 685 /** 686 * Retrieve a logger by name in current encoding. 687 * @param name logger name. 688 */ 689 static LoggerPtr getLogger(const std::string& name); 690 /** 691 * Retrieve a logger by name in current encoding. 692 * @param name logger name. 693 */ 694 static LoggerPtr getLogger(const char* const name); 695 #if LOG4CXX_WCHAR_T_API 696 /** 697 * Retrieve a logger by name. 698 * @param name logger name. 699 */ 700 static LoggerPtr getLogger(const std::wstring& name); 701 /** 702 * Retrieve a logger by name. 703 * @param name logger name. 704 */ 705 static LoggerPtr getLogger(const wchar_t* const name); 706 #endif 707 #if LOG4CXX_UNICHAR_API 708 /** 709 * Retrieve a logger by name. 710 * @param name logger name. 711 */ 712 static LoggerPtr getLogger(const std::basic_string<UniChar>& name); 713 #endif 714 #if LOG4CXX_CFSTRING_API 715 /** 716 * Retrieve a logger by name. 717 * @param name logger name. 718 */ 719 static LoggerPtr getLogger(const CFStringRef& name); 720 #endif 721 /** 722 * Retrieve a logger by name in Unicode. 723 * @param name logger name. 724 */ 725 static LoggerPtr getLoggerLS(const LogString& name); 726 727 /** 728 Retrieve the root logger. 729 */ 730 static LoggerPtr getRootLogger(); 731 732 /** 733 Like #getLogger except that the type of logger 734 instantiated depends on the type returned by the 735 LoggerFactory#makeNewLoggerInstance method of the 736 <code>factory</code> parameter. 737 738 <p>This method is intended to be used by sub-classes. 739 740 @param name The name of the logger to retrieve. 741 742 @param factory A LoggerFactory implementation that will 743 actually create a new Instance. 744 */ 745 static LoggerPtr getLoggerLS(const LogString& name, 746 const log4cxx::spi::LoggerFactoryPtr& factory); 747 /** 748 Like #getLogger except that the type of logger 749 instantiated depends on the type returned by the 750 LoggerFactory#makeNewLoggerInstance method of the 751 <code>factory</code> parameter. 752 753 <p>This method is intended to be used by sub-classes. 754 755 @param name The name of the logger to retrieve. 756 757 @param factory A LoggerFactory implementation that will 758 actually create a new Instance. 759 */ 760 static LoggerPtr getLogger(const std::string& name, 761 const log4cxx::spi::LoggerFactoryPtr& factory); 762 #if LOG4CXX_WCHAR_T_API 763 /** 764 Like #getLogger except that the type of logger 765 instantiated depends on the type returned by the 766 LoggerFactory#makeNewLoggerInstance method of the 767 <code>factory</code> parameter. 768 769 <p>This method is intended to be used by sub-classes. 770 771 @param name The name of the logger to retrieve. 772 773 @param factory A LoggerFactory implementation that will 774 actually create a new Instance. 775 */ 776 static LoggerPtr getLogger(const std::wstring& name, 777 const log4cxx::spi::LoggerFactoryPtr& factory); 778 #endif 779 #if LOG4CXX_UNICHAR_API 780 /** 781 Like #getLogger except that the type of logger 782 instantiated depends on the type returned by the 783 LoggerFactory#makeNewLoggerInstance method of the 784 <code>factory</code> parameter. 785 786 <p>This method is intended to be used by sub-classes. 787 788 @param name The name of the logger to retrieve. 789 790 @param factory A LoggerFactory implementation that will 791 actually create a new Instance. 792 */ 793 static LoggerPtr getLogger(const std::basic_string<UniChar>& name, 794 const log4cxx::spi::LoggerFactoryPtr& factory); 795 #endif 796 #if LOG4CXX_CFSTRING_API 797 /** 798 Like #getLogger except that the type of logger 799 instantiated depends on the type returned by the 800 LoggerFactory#makeNewLoggerInstance method of the 801 <code>factory</code> parameter. 802 803 <p>This method is intended to be used by sub-classes. 804 805 @param name The name of the logger to retrieve. 806 807 @param factory A LoggerFactory implementation that will 808 actually create a new Instance. 809 */ 810 static LoggerPtr getLogger(const CFStringRef& name, 811 const log4cxx::spi::LoggerFactoryPtr& factory); 812 #endif 813 814 /** 815 Return the <em>inherited</em> ResourceBundle for this logger. 816 817 818 This method walks the hierarchy to find the appropriate resource bundle. 819 It will return the resource bundle attached to the closest ancestor of 820 this logger, much like the way priorities are searched. In case there 821 is no bundle in the hierarchy then <code>NULL</code> is returned. 822 */ 823 helpers::ResourceBundlePtr getResourceBundle() const; 824 825 protected: 826 /** 827 Returns the string resource coresponding to <code>key</code> in this 828 logger's inherited resource bundle. 829 830 If the resource cannot be found, then an {@link #error error} message 831 will be logged complaining about the missing resource. 832 833 @see #getResourceBundle. 834 */ 835 LogString getResourceBundleString(const LogString& key) const; 836 837 public: 838 /** 839 Log a message string with the INFO level. 840 841 <p>This method first checks if this logger is <code>INFO</code> 842 enabled by comparing the level of this logger with the 843 INFO level. If this logger is 844 <code>INFO</code> enabled, it proceeds to call all the 845 registered appenders in this logger and also higher in the 846 hierarchy depending on the value of the additivity flag. 847 848 @param msg the message string to log. 849 @param location location of source of logging request. 850 */ 851 void info(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; 852 void info(const std::string& msg) const; 853 #if LOG4CXX_WCHAR_T_API 854 /** 855 Log a message string with the INFO level. 856 857 <p>This method first checks if this logger is <code>INFO</code> 858 enabled by comparing the level of this logger with the 859 INFO level. If this logger is 860 <code>INFO</code> enabled, it proceeds to call all the 861 registered appenders in this logger and also higher in the 862 hierarchy depending on the value of the additivity flag. 863 864 @param msg the message string to log. 865 @param location location of source of logging request. 866 */ 867 void info(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; 868 /** 869 Log a message string with the INFO level. 870 871 <p>This method first checks if this logger is <code>INFO</code> 872 enabled by comparing the level of this logger with the 873 INFO level. If this logger is 874 <code>INFO</code> enabled, it proceeds to call all the 875 registered appenders in this logger and also higher in the 876 hierarchy depending on the value of the additivity flag. 877 878 @param msg the message string to log. 879 */ 880 void info(const std::wstring& msg) const; 881 #endif 882 #if LOG4CXX_UNICHAR_API 883 /** 884 Log a message string with the INFO level. 885 886 <p>This method first checks if this logger is <code>INFO</code> 887 enabled by comparing the level of this logger with the 888 INFO level. If this logger is 889 <code>INFO</code> enabled, it proceeds to call all the 890 registered appenders in this logger and also higher in the 891 hierarchy depending on the value of the additivity flag. 892 893 @param msg the message string to log. 894 @param location location of source of logging request. 895 */ 896 void info(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; 897 /** 898 Log a message string with the INFO level. 899 900 <p>This method first checks if this logger is <code>INFO</code> 901 enabled by comparing the level of this logger with the 902 INFO level. If this logger is 903 <code>INFO</code> enabled, it proceeds to call all the 904 registered appenders in this logger and also higher in the 905 hierarchy depending on the value of the additivity flag. 906 907 @param msg the message string to log. 908 */ 909 void info(const std::basic_string<UniChar>& msg) const; 910 #endif 911 #if LOG4CXX_CFSTRING_API 912 /** 913 Log a message string with the INFO level. 914 915 <p>This method first checks if this logger is <code>INFO</code> 916 enabled by comparing the level of this logger with the 917 INFO level. If this logger is 918 <code>INFO</code> enabled, it proceeds to call all the 919 registered appenders in this logger and also higher in the 920 hierarchy depending on the value of the additivity flag. 921 922 @param msg the message string to log. 923 @param location location of source of logging request. 924 */ 925 void info(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; 926 /** 927 Log a message string with the INFO level. 928 929 <p>This method first checks if this logger is <code>INFO</code> 930 enabled by comparing the level of this logger with the 931 INFO level. If this logger is 932 <code>INFO</code> enabled, it proceeds to call all the 933 registered appenders in this logger and also higher in the 934 hierarchy depending on the value of the additivity flag. 935 936 @param msg the message string to log. 937 */ 938 void info(const CFStringRef& msg) const; 939 #endif 940 941 /** 942 Is the appender passed as parameter attached to this logger? 943 */ 944 bool isAttached(const AppenderPtr& appender) const; 945 946 /** 947 * Check whether this logger is enabled for the <code>DEBUG</code> 948 * Level. 949 * 950 * <p> This function is intended to lessen the computational cost of 951 * disabled log debug statements. 952 * 953 * <p> For some <code>logger</code> Logger object, when you write, 954 * <pre> 955 * logger->debug("debug message"); 956 * </pre> 957 * 958 * <p>You incur the cost constructing the message, concatenation in 959 * this case, regardless of whether the message is logged or not. 960 * 961 * <p>If you are worried about speed, then you should write 962 * <pre> 963 * if(logger->isDebugEnabled()) { 964 * logger->debug("debug message"); 965 * } 966 * </pre> 967 * 968 * <p>This way you will not incur the cost of parameter 969 * construction if debugging is disabled for <code>logger</code>. On 970 * the other hand, if the <code>logger</code> is debug enabled, you 971 * will incur the cost of evaluating whether the logger is debug 972 * enabled twice. Once in <code>isDebugEnabled</code> and once in 973 * the <code>debug</code>. This is an insignificant overhead 974 * since evaluating a logger takes about 1%% of the time it 975 * takes to actually log. 976 * 977 * @return bool - <code>true</code> if this logger is debug 978 * enabled, <code>false</code> otherwise. 979 * */ 980 bool isDebugEnabled() const; 981 982 /** 983 Check whether this logger is enabled for a given 984 Level passed as parameter. 985 986 See also #isDebugEnabled. 987 988 @return bool True if this logger is enabled for <code>level</code>. 989 */ 990 bool isEnabledFor(const LevelPtr& level) const; 991 992 993 /** 994 Check whether this logger is enabled for the info Level. 995 See also #isDebugEnabled. 996 997 @return bool - <code>true</code> if this logger is enabled 998 for level info, <code>false</code> otherwise. 999 */ 1000 bool isInfoEnabled() const; 1001 1002 /** 1003 Check whether this logger is enabled for the warn Level. 1004 See also #isDebugEnabled. 1005 1006 @return bool - <code>true</code> if this logger is enabled 1007 for level warn, <code>false</code> otherwise. 1008 */ 1009 bool isWarnEnabled() const; 1010 1011 /** 1012 Check whether this logger is enabled for the error Level. 1013 See also #isDebugEnabled. 1014 1015 @return bool - <code>true</code> if this logger is enabled 1016 for level error, <code>false</code> otherwise. 1017 */ 1018 bool isErrorEnabled() const; 1019 1020 /** 1021 Check whether this logger is enabled for the fatal Level. 1022 See also #isDebugEnabled. 1023 1024 @return bool - <code>true</code> if this logger is enabled 1025 for level fatal, <code>false</code> otherwise. 1026 */ 1027 bool isFatalEnabled() const; 1028 1029 /** 1030 Check whether this logger is enabled for the trace level. 1031 See also #isDebugEnabled. 1032 1033 @return bool - <code>true</code> if this logger is enabled 1034 for level trace, <code>false</code> otherwise. 1035 */ 1036 bool isTraceEnabled() const; 1037 1038 /** 1039 Log a localized and parameterized message. 1040 1041 First, the user supplied 1042 <code>key</code> is searched in the resource bundle. Next, the resulting 1043 pattern is formatted using helpers::StringHelper::format method with the user 1044 supplied string array <code>params</code>. 1045 1046 @param level The level of the logging request. 1047 @param key The key to be searched in the ResourceBundle. 1048 @param locationInfo The location info of the logging request. 1049 @param values The values for the placeholders <code>{0}</code>, 1050 <code>{1}</code> etc. within the pattern. 1051 1052 @see #setResourceBundle 1053 */ 1054 void l7dlog(const LevelPtr& level, const LogString& key, 1055 const log4cxx::spi::LocationInfo& locationInfo, 1056 const std::vector<LogString>& values) const; 1057 /** 1058 Log a localized and parameterized message. 1059 1060 First, the user supplied 1061 <code>key</code> is searched in the resource bundle. Next, the resulting 1062 pattern is formatted using helpers::StringHelper::format method with the user 1063 supplied string array <code>params</code>. 1064 1065 @param level The level of the logging request. 1066 @param key The key to be searched in the ResourceBundle. 1067 @param locationInfo The location info of the logging request. 1068 1069 @see #setResourceBundle 1070 */ 1071 void l7dlog(const LevelPtr& level, const std::string& key, 1072 const log4cxx::spi::LocationInfo& locationInfo) const; 1073 /** 1074 Log a localized and parameterized message. 1075 1076 First, the user supplied 1077 <code>key</code> is searched in the resource bundle. Next, the resulting 1078 pattern is formatted using helpers::StringHelper::format method with the user 1079 supplied string array <code>params</code>. 1080 1081 @param level The level of the logging request. 1082 @param key The key to be searched in the ResourceBundle. 1083 @param locationInfo The location info of the logging request. 1084 @param val1 The first value for the placeholders within the pattern. 1085 1086 @see #setResourceBundle 1087 */ 1088 void l7dlog(const LevelPtr& level, const std::string& key, 1089 const log4cxx::spi::LocationInfo& locationInfo, 1090 const std::string& val1) const; 1091 /** 1092 Log a localized and parameterized message. 1093 1094 First, the user supplied 1095 <code>key</code> is searched in the resource bundle. Next, the resulting 1096 pattern is formatted using helpers::StringHelper::format method with the user 1097 supplied string array <code>params</code>. 1098 1099 @param level The level of the logging request. 1100 @param key The key to be searched in the ResourceBundle. 1101 @param locationInfo The location info of the logging request. 1102 @param val1 The first value for the placeholders within the pattern. 1103 @param val2 The second value for the placeholders within the pattern. 1104 1105 @see #setResourceBundle 1106 */ 1107 void l7dlog(const LevelPtr& level, const std::string& key, 1108 const log4cxx::spi::LocationInfo& locationInfo, 1109 const std::string& val1, const std::string& val2) const; 1110 /** 1111 Log a localized and parameterized message. 1112 1113 First, the user supplied 1114 <code>key</code> is searched in the resource bundle. Next, the resulting 1115 pattern is formatted using helpers::StringHelper::format method with the user 1116 supplied string array <code>params</code>. 1117 1118 @param level The level of the logging request. 1119 @param key The key to be searched in the ResourceBundle. 1120 @param locationInfo The location info of the logging request. 1121 @param val1 The value for the first placeholder within the pattern. 1122 @param val2 The value for the second placeholder within the pattern. 1123 @param val3 The value for the third placeholder within the pattern. 1124 1125 @see #setResourceBundle 1126 */ 1127 void l7dlog(const LevelPtr& level, const std::string& key, 1128 const log4cxx::spi::LocationInfo& locationInfo, 1129 const std::string& val1, const std::string& val2, const std::string& val3) const; 1130 1131 #if LOG4CXX_WCHAR_T_API 1132 /** 1133 Log a localized and parameterized message. 1134 1135 First, the user supplied 1136 <code>key</code> is searched in the resource bundle. Next, the resulting 1137 pattern is formatted using helpers::StringHelper::format method with the user 1138 supplied string array <code>params</code>. 1139 1140 @param level The level of the logging request. 1141 @param key The key to be searched in the ResourceBundle. 1142 @param locationInfo The location info of the logging request. 1143 1144 @see #setResourceBundle 1145 */ 1146 void l7dlog(const LevelPtr& level, const std::wstring& key, 1147 const log4cxx::spi::LocationInfo& locationInfo) const; 1148 /** 1149 Log a localized and parameterized message. 1150 1151 First, the user supplied 1152 <code>key</code> is searched in the resource bundle. Next, the resulting 1153 pattern is formatted using helpers::StringHelper::format method with the user 1154 supplied string array <code>params</code>. 1155 1156 @param level The level of the logging request. 1157 @param key The key to be searched in the ResourceBundle. 1158 @param locationInfo The location info of the logging request. 1159 @param val1 The value for the first placeholder within the pattern. 1160 1161 @see #setResourceBundle 1162 */ 1163 void l7dlog(const LevelPtr& level, const std::wstring& key, 1164 const log4cxx::spi::LocationInfo& locationInfo, 1165 const std::wstring& val1) const; 1166 /** 1167 Log a localized and parameterized message. 1168 1169 First, the user supplied 1170 <code>key</code> is searched in the resource bundle. Next, the resulting 1171 pattern is formatted using helpers::StringHelper::format method with the user 1172 supplied string array <code>params</code>. 1173 1174 @param level The level of the logging request. 1175 @param key The key to be searched in the ResourceBundle. 1176 @param locationInfo The location info of the logging request. 1177 @param val1 The value for the first placeholder within the pattern. 1178 @param val2 The value for the second placeholder within the pattern. 1179 1180 @see #setResourceBundle 1181 */ 1182 void l7dlog(const LevelPtr& level, const std::wstring& key, 1183 const log4cxx::spi::LocationInfo& locationInfo, 1184 const std::wstring& val1, const std::wstring& val2) const; 1185 /** 1186 Log a localized and parameterized message. 1187 1188 First, the user supplied 1189 <code>key</code> is searched in the resource bundle. Next, the resulting 1190 pattern is formatted using helpers::StringHelper::format method with the user 1191 supplied string array <code>params</code>. 1192 1193 @param level The level of the logging request. 1194 @param key The key to be searched in the ResourceBundle. 1195 @param locationInfo The location info of the logging request. 1196 @param val1 The value for the first placeholder within the pattern. 1197 @param val2 The value for the second placeholder within the pattern. 1198 @param val3 The value for the third placeholder within the pattern. 1199 1200 @see #setResourceBundle 1201 */ 1202 void l7dlog(const LevelPtr& level, const std::wstring& key, 1203 const log4cxx::spi::LocationInfo& locationInfo, 1204 const std::wstring& val1, const std::wstring& val2, const std::wstring& val3) const; 1205 #endif 1206 #if LOG4CXX_UNICHAR_API 1207 /** 1208 Log a localized and parameterized message. 1209 1210 First, the user supplied 1211 <code>key</code> is searched in the resource bundle. Next, the resulting 1212 pattern is formatted using helpers::StringHelper::format method with the user 1213 supplied string array <code>params</code>. 1214 1215 @param level The level of the logging request. 1216 @param key The key to be searched in the ResourceBundle. 1217 @param locationInfo The location info of the logging request. 1218 1219 @see #setResourceBundle 1220 */ 1221 void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, 1222 const log4cxx::spi::LocationInfo& locationInfo) const; 1223 /** 1224 Log a localized and parameterized message. 1225 1226 First, the user supplied 1227 <code>key</code> is searched in the resource bundle. Next, the resulting 1228 pattern is formatted using helpers::StringHelper::format method with the user 1229 supplied string array <code>params</code>. 1230 1231 @param level The level of the logging request. 1232 @param key The key to be searched in the ResourceBundle. 1233 @param locationInfo The location info of the logging request. 1234 @param val1 The value for the first placeholder within the pattern. 1235 1236 @see #setResourceBundle 1237 */ 1238 void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, 1239 const log4cxx::spi::LocationInfo& locationInfo, 1240 const std::basic_string<UniChar>& val1) const; 1241 /** 1242 Log a localized and parameterized message. 1243 1244 First, the user supplied 1245 <code>key</code> is searched in the resource bundle. Next, the resulting 1246 pattern is formatted using helpers::StringHelper::format method with the user 1247 supplied string array <code>params</code>. 1248 1249 @param level The level of the logging request. 1250 @param key The key to be searched in the ResourceBundle. 1251 @param locationInfo The location info of the logging request. 1252 @param val1 The value for the first placeholder within the pattern. 1253 @param val2 The value for the second placeholder within the pattern. 1254 1255 @see #setResourceBundle 1256 */ 1257 void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, 1258 const log4cxx::spi::LocationInfo& locationInfo, 1259 const std::basic_string<UniChar>& val1, const std::basic_string<UniChar>& val2) const; 1260 /** 1261 Log a localized and parameterized message. 1262 1263 First, the user supplied 1264 <code>key</code> is searched in the resource bundle. Next, the resulting 1265 pattern is formatted using helpers::StringHelper::format method with the user 1266 supplied string array <code>params</code>. 1267 1268 @param level The level of the logging request. 1269 @param key The key to be searched in the ResourceBundle. 1270 @param locationInfo The location info of the logging request. 1271 @param val1 The value for the first placeholder within the pattern. 1272 @param val2 The value for the second placeholder within the pattern. 1273 @param val3 The value for the third placeholder within the pattern. 1274 1275 @see #setResourceBundle 1276 */ 1277 void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, 1278 const log4cxx::spi::LocationInfo& locationInfo, 1279 const std::basic_string<UniChar>& val1, const std::basic_string<UniChar>& val2, 1280 const std::basic_string<UniChar>& val3) const; 1281 #endif 1282 #if LOG4CXX_CFSTRING_API 1283 /** 1284 Log a localized and parameterized message. 1285 1286 First, the user supplied 1287 <code>key</code> is searched in the resource bundle. Next, the resulting 1288 pattern is formatted using helpers::StringHelper::format method with the user 1289 supplied string array <code>params</code>. 1290 1291 @param level The level of the logging request. 1292 @param key The key to be searched in the ResourceBundle. 1293 @param locationInfo The location info of the logging request. 1294 1295 @see #setResourceBundle 1296 */ 1297 void l7dlog(const LevelPtr& level, const CFStringRef& key, 1298 const log4cxx::spi::LocationInfo& locationInfo) const; 1299 /** 1300 Log a localized and parameterized message. 1301 1302 First, the user supplied 1303 <code>key</code> is searched in the resource bundle. Next, the resulting 1304 pattern is formatted using helpers::StringHelper::format method with the user 1305 supplied string array <code>params</code>. 1306 1307 @param level The level of the logging request. 1308 @param key The key to be searched in the ResourceBundle. 1309 @param locationInfo The location info of the logging request. 1310 @param val1 The value for the first placeholder within the pattern. 1311 1312 @see #setResourceBundle 1313 */ 1314 void l7dlog(const LevelPtr& level, const CFStringRef& key, 1315 const log4cxx::spi::LocationInfo& locationInfo, 1316 const CFStringRef& val1) const; 1317 /** 1318 Log a localized and parameterized message. 1319 1320 First, the user supplied 1321 <code>key</code> is searched in the resource bundle. Next, the resulting 1322 pattern is formatted using helpers::StringHelper::format method with the user 1323 supplied string array <code>params</code>. 1324 1325 @param level The level of the logging request. 1326 @param key The key to be searched in the ResourceBundle. 1327 @param locationInfo The location info of the logging request. 1328 @param val1 The value for the first placeholder within the pattern. 1329 @param val2 The value for the second placeholder within the pattern. 1330 1331 @see #setResourceBundle 1332 */ 1333 void l7dlog(const LevelPtr& level, const CFStringRef& key, 1334 const log4cxx::spi::LocationInfo& locationInfo, 1335 const CFStringRef& val1, const CFStringRef& val2) const; 1336 /** 1337 Log a localized and parameterized message. 1338 1339 First, the user supplied 1340 <code>key</code> is searched in the resource bundle. Next, the resulting 1341 pattern is formatted using helpers::StringHelper::format method with the user 1342 supplied string array <code>params</code>. 1343 1344 @param level The level of the logging request. 1345 @param key The key to be searched in the ResourceBundle. 1346 @param locationInfo The location info of the logging request. 1347 @param val1 The value for the first placeholder within the pattern. 1348 @param val2 The value for the second placeholder within the pattern. 1349 @param val3 The value for the third placeholder within the pattern. 1350 1351 @see #setResourceBundle 1352 */ 1353 void l7dlog(const LevelPtr& level, const CFStringRef& key, 1354 const log4cxx::spi::LocationInfo& locationInfo, 1355 const CFStringRef& val1, const CFStringRef& val2, 1356 const CFStringRef& val3) const; 1357 #endif 1358 1359 /** 1360 This is the most generic printing method. It is intended to be 1361 invoked by <b>wrapper</b> classes. 1362 1363 @param level The level of the logging request. 1364 @param message The message of the logging request. 1365 @param location The source file of the logging request, may be null. */ 1366 void log(const LevelPtr& level, const std::string& message, 1367 const log4cxx::spi::LocationInfo& location) const; 1368 /** 1369 This is the most generic printing method. It is intended to be 1370 invoked by <b>wrapper</b> classes. 1371 1372 @param level The level of the logging request. 1373 @param message The message of the logging request. 1374 */ 1375 void log(const LevelPtr& level, const std::string& message) const; 1376 #if LOG4CXX_WCHAR_T_API 1377 /** 1378 This is the most generic printing method. It is intended to be 1379 invoked by <b>wrapper</b> classes. 1380 1381 @param level The level of the logging request. 1382 @param message The message of the logging request. 1383 @param location The source file of the logging request, may be null. */ 1384 void log(const LevelPtr& level, const std::wstring& message, 1385 const log4cxx::spi::LocationInfo& location) const; 1386 /** 1387 This is the most generic printing method. It is intended to be 1388 invoked by <b>wrapper</b> classes. 1389 1390 @param level The level of the logging request. 1391 @param message The message of the logging request. 1392 */ 1393 void log(const LevelPtr& level, const std::wstring& message) const; 1394 #endif 1395 #if LOG4CXX_UNICHAR_API 1396 /** 1397 This is the most generic printing method. It is intended to be 1398 invoked by <b>wrapper</b> classes. 1399 1400 @param level The level of the logging request. 1401 @param message The message of the logging request. 1402 @param location The source file of the logging request, may be null. */ 1403 void log(const LevelPtr& level, const std::basic_string<UniChar>& message, 1404 const log4cxx::spi::LocationInfo& location) const; 1405 /** 1406 This is the most generic printing method. It is intended to be 1407 invoked by <b>wrapper</b> classes. 1408 1409 @param level The level of the logging request. 1410 @param message The message of the logging request. 1411 */ 1412 void log(const LevelPtr& level, const std::basic_string<UniChar>& message) const; 1413 #endif 1414 #if LOG4CXX_CFSTRING_API 1415 /** 1416 This is the most generic printing method. It is intended to be 1417 invoked by <b>wrapper</b> classes. 1418 1419 @param level The level of the logging request. 1420 @param message The message of the logging request. 1421 @param location The source file of the logging request, may be null. */ 1422 void log(const LevelPtr& level, const CFStringRef& message, 1423 const log4cxx::spi::LocationInfo& location) const; 1424 /** 1425 This is the most generic printing method. It is intended to be 1426 invoked by <b>wrapper</b> classes. 1427 1428 @param level The level of the logging request. 1429 @param message The message of the logging request. 1430 */ 1431 void log(const LevelPtr& level, const CFStringRef& message) const; 1432 #endif 1433 /** 1434 This is the most generic printing method. It is intended to be 1435 invoked by <b>wrapper</b> classes. 1436 1437 @param level The level of the logging request. 1438 @param message The message of the logging request. 1439 @param location The source file of the logging request, may be null. */ 1440 void logLS(const LevelPtr& level, const LogString& message, 1441 const log4cxx::spi::LocationInfo& location) const; 1442 1443 1444 1445 /** 1446 Remove all previously added appenders from this logger 1447 instance. 1448 <p>This is useful when re-reading configuration information. 1449 */ 1450 void removeAllAppenders(); 1451 1452 /** 1453 Remove the appender passed as parameter form the list of appenders. 1454 */ 1455 void removeAppender(const AppenderPtr& appender); 1456 1457 /** 1458 Remove the appender with the name passed as parameter form the 1459 list of appenders. 1460 */ 1461 void removeAppender(const LogString& name); 1462 1463 /** 1464 Set the additivity flag for this Logger instance. 1465 */ 1466 void setAdditivity(bool additive); 1467 1468 protected: 1469 friend class Hierarchy; 1470 /** 1471 Only the Hierarchy class can set the hierarchy of a logger.*/ 1472 void setHierarchy(spi::LoggerRepository* repository); 1473 1474 public: 1475 /** 1476 Set the level of this Logger. 1477 1478 <p>As in <pre> logger->setLevel(Level::getDebug()); </pre> 1479 1480 <p>Null values are admitted. */ 1481 virtual void setLevel(const LevelPtr& level); 1482 1483 /** 1484 Set the resource bundle to be used with localized logging methods. 1485 */ setResourceBundle(const helpers::ResourceBundlePtr & bundle)1486 inline void setResourceBundle(const helpers::ResourceBundlePtr& bundle) 1487 { 1488 resourceBundle = bundle; 1489 } 1490 1491 #if LOG4CXX_WCHAR_T_API 1492 /** 1493 Log a message string with the WARN level. 1494 1495 <p>This method first checks if this logger is <code>WARN</code> 1496 enabled by comparing the level of this logger with the 1497 WARN level. If this logger is 1498 <code>WARN</code> enabled, it proceeds to call all the 1499 registered appenders in this logger and also higher in the 1500 hierarchy depending on the value of the additivity flag. 1501 1502 @param msg the message string to log. 1503 @param location location of source of logging request. 1504 */ 1505 void warn(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; 1506 /** 1507 Log a message string with the WARN level. 1508 1509 <p>This method first checks if this logger is <code>WARN</code> 1510 enabled by comparing the level of this logger with the 1511 WARN level. If this logger is 1512 <code>WARN</code> enabled, it proceeds to call all the 1513 registered appenders in this logger and also higher in the 1514 hierarchy depending on the value of the additivity flag. 1515 1516 @param msg the message string to log. 1517 */ 1518 void warn(const std::wstring& msg) const; 1519 #endif 1520 #if LOG4CXX_UNICHAR_API 1521 /** 1522 Log a message string with the WARN level. 1523 1524 <p>This method first checks if this logger is <code>WARN</code> 1525 enabled by comparing the level of this logger with the 1526 WARN level. If this logger is 1527 <code>WARN</code> enabled, it proceeds to call all the 1528 registered appenders in this logger and also higher in the 1529 hierarchy depending on the value of the additivity flag. 1530 1531 @param msg the message string to log. 1532 @param location location of source of logging request. 1533 */ 1534 void warn(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; 1535 /** 1536 Log a message string with the WARN level. 1537 1538 <p>This method first checks if this logger is <code>WARN</code> 1539 enabled by comparing the level of this logger with the 1540 WARN level. If this logger is 1541 <code>WARN</code> enabled, it proceeds to call all the 1542 registered appenders in this logger and also higher in the 1543 hierarchy depending on the value of the additivity flag. 1544 1545 @param msg the message string to log. 1546 */ 1547 void warn(const std::basic_string<UniChar>& msg) const; 1548 #endif 1549 #if LOG4CXX_CFSTRING_API 1550 /** 1551 Log a message string with the WARN level. 1552 1553 <p>This method first checks if this logger is <code>WARN</code> 1554 enabled by comparing the level of this logger with the 1555 WARN level. If this logger is 1556 <code>WARN</code> enabled, it proceeds to call all the 1557 registered appenders in this logger and also higher in the 1558 hierarchy depending on the value of the additivity flag. 1559 1560 @param msg the message string to log. 1561 @param location location of source of logging request. 1562 */ 1563 void warn(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; 1564 /** 1565 Log a message string with the WARN level. 1566 1567 <p>This method first checks if this logger is <code>WARN</code> 1568 enabled by comparing the level of this logger with the 1569 WARN level. If this logger is 1570 <code>WARN</code> enabled, it proceeds to call all the 1571 registered appenders in this logger and also higher in the 1572 hierarchy depending on the value of the additivity flag. 1573 1574 @param msg the message string to log. 1575 */ 1576 void warn(const CFStringRef& msg) const; 1577 #endif 1578 /** 1579 Log a message string with the WARN level. 1580 1581 <p>This method first checks if this logger is <code>WARN</code> 1582 enabled by comparing the level of this logger with the 1583 WARN level. If this logger is 1584 <code>WARN</code> enabled, it proceeds to call all the 1585 registered appenders in this logger and also higher in the 1586 hierarchy depending on the value of the additivity flag. 1587 1588 @param msg the message string to log. 1589 @param location location of source of logging request. 1590 */ 1591 void warn(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; 1592 /** 1593 Log a message string with the WARN level. 1594 1595 <p>This method first checks if this logger is <code>WARN</code> 1596 enabled by comparing the level of this logger with the 1597 WARN level. If this logger is 1598 <code>WARN</code> enabled, it proceeds to call all the 1599 registered appenders in this logger and also higher in the 1600 hierarchy depending on the value of the additivity flag. 1601 1602 @param msg the message string to log. 1603 */ 1604 void warn(const std::string& msg) const; 1605 1606 #if LOG4CXX_WCHAR_T_API 1607 /** 1608 Log a message string with the TRACE level. 1609 1610 <p>This method first checks if this logger is <code>TRACE</code> 1611 enabled by comparing the level of this logger with the 1612 TRACE level. If this logger is 1613 <code>TRACE</code> enabled, it proceeds to call all the 1614 registered appenders in this logger and also higher in the 1615 hierarchy depending on the value of the additivity flag. 1616 1617 @param msg the message string to log. 1618 @param location location of source of logging request. 1619 */ 1620 void trace(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; 1621 /** 1622 Log a message string with the TRACE level. 1623 1624 <p>This method first checks if this logger is <code>TRACE</code> 1625 enabled by comparing the level of this logger with the 1626 TRACE level. If this logger is 1627 <code>TRACE</code> enabled, it proceeds to call all the 1628 registered appenders in this logger and also higher in the 1629 hierarchy depending on the value of the additivity flag. 1630 1631 @param msg the message string to log. 1632 */ 1633 void trace(const std::wstring& msg) const; 1634 #endif 1635 #if LOG4CXX_UNICHAR_API 1636 /** 1637 Log a message string with the TRACE level. 1638 1639 <p>This method first checks if this logger is <code>TRACE</code> 1640 enabled by comparing the level of this logger with the 1641 TRACE level. If this logger is 1642 <code>TRACE</code> enabled, it proceeds to call all the 1643 registered appenders in this logger and also higher in the 1644 hierarchy depending on the value of the additivity flag. 1645 1646 @param msg the message string to log. 1647 @param location location of source of logging request. 1648 */ 1649 void trace(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; 1650 /** 1651 Log a message string with the TRACE level. 1652 1653 <p>This method first checks if this logger is <code>TRACE</code> 1654 enabled by comparing the level of this logger with the 1655 TRACE level. If this logger is 1656 <code>TRACE</code> enabled, it proceeds to call all the 1657 registered appenders in this logger and also higher in the 1658 hierarchy depending on the value of the additivity flag. 1659 1660 @param msg the message string to log. 1661 */ 1662 void trace(const std::basic_string<UniChar>& msg) const; 1663 #endif 1664 #if LOG4CXX_CFSTRING_API 1665 /** 1666 Log a message string with the TRACE level. 1667 1668 <p>This method first checks if this logger is <code>TRACE</code> 1669 enabled by comparing the level of this logger with the 1670 TRACE level. If this logger is 1671 <code>TRACE</code> enabled, it proceeds to call all the 1672 registered appenders in this logger and also higher in the 1673 hierarchy depending on the value of the additivity flag. 1674 1675 @param msg the message string to log. 1676 @param location location of source of logging request. 1677 */ 1678 void trace(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; 1679 /** 1680 Log a message string with the TRACE level. 1681 1682 <p>This method first checks if this logger is <code>TRACE</code> 1683 enabled by comparing the level of this logger with the 1684 TRACE level. If this logger is 1685 <code>TRACE</code> enabled, it proceeds to call all the 1686 registered appenders in this logger and also higher in the 1687 hierarchy depending on the value of the additivity flag. 1688 1689 @param msg the message string to log. 1690 */ 1691 void trace(const CFStringRef& msg) const; 1692 #endif 1693 /** 1694 Log a message string with the TRACE level. 1695 1696 <p>This method first checks if this logger is <code>TRACE</code> 1697 enabled by comparing the level of this logger with the 1698 TRACE level. If this logger is 1699 <code>TRACE</code> enabled, it proceeds to call all the 1700 registered appenders in this logger and also higher in the 1701 hierarchy depending on the value of the additivity flag. 1702 1703 @param msg the message string to log. 1704 @param location location of source of logging request. 1705 */ 1706 void trace(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; 1707 /** 1708 Log a message string with the TRACE level. 1709 1710 <p>This method first checks if this logger is <code>TRACE</code> 1711 enabled by comparing the level of this logger with the 1712 TRACE level. If this logger is 1713 <code>TRACE</code> enabled, it proceeds to call all the 1714 registered appenders in this logger and also higher in the 1715 hierarchy depending on the value of the additivity flag. 1716 1717 @param msg the message string to log. 1718 */ 1719 void trace(const std::string& msg) const; 1720 getMutex()1721 inline SHARED_MUTEX& getMutex() 1722 { 1723 return mutex; 1724 } 1725 1726 private: 1727 // 1728 // prevent copy and assignment 1729 Logger(const Logger&); 1730 Logger& operator=(const Logger&); 1731 mutable SHARED_MUTEX mutex; 1732 friend class log4cxx::helpers::synchronized; 1733 }; 1734 LOG4CXX_LIST_DEF(LoggerList, LoggerPtr); 1735 1736 } 1737 1738 /** @addtogroup LoggingMacros Logging macros 1739 @{ 1740 */ 1741 1742 #if !defined(LOG4CXX_UNLIKELY) 1743 #if __GNUC__ >= 3 1744 /** 1745 Provides optimization hint to the compiler 1746 to optimize for the expression being false. 1747 @param expr boolean expression. 1748 @returns value of expression. 1749 */ 1750 #define LOG4CXX_UNLIKELY(expr) __builtin_expect(expr, 0) 1751 #else 1752 /** 1753 Provides optimization hint to the compiler 1754 to optimize for the expression being false. 1755 @param expr boolean expression. 1756 @returns value of expression. 1757 **/ 1758 #define LOG4CXX_UNLIKELY(expr) expr 1759 #endif 1760 #endif 1761 1762 1763 /** 1764 Logs a message to a specified logger with a specified level. 1765 1766 @param logger the logger to be used. 1767 @param level the level to log. 1768 @param message the message string to log. 1769 */ 1770 #define LOG4CXX_LOG(logger, level, message) do { \ 1771 if (logger->isEnabledFor(level)) {\ 1772 ::log4cxx::helpers::MessageBuffer oss_; \ 1773 logger->forcedLog(level, oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1774 1775 /** 1776 Logs a message to a specified logger with a specified level. 1777 1778 @param logger the logger to be used. 1779 @param level the level to log. 1780 @param message the message string to log in the internal encoding. 1781 */ 1782 #define LOG4CXX_LOGLS(logger, level, message) do { \ 1783 if (logger->isEnabledFor(level)) {\ 1784 ::log4cxx::helpers::LogCharMessageBuffer oss_; \ 1785 logger->forcedLog(level, oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1786 1787 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 10000 1788 /** 1789 Logs a message to a specified logger with the DEBUG level. 1790 1791 @param logger the logger to be used. 1792 @param message the message string to log. 1793 */ 1794 #define LOG4CXX_DEBUG(logger, message) do { \ 1795 if (LOG4CXX_UNLIKELY(logger->isDebugEnabled())) {\ 1796 ::log4cxx::helpers::MessageBuffer oss_; \ 1797 logger->forcedLog(::log4cxx::Level::getDebug(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1798 #else 1799 #define LOG4CXX_DEBUG(logger, message) 1800 #endif 1801 1802 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 5000 1803 /** 1804 Logs a message to a specified logger with the TRACE level. 1805 1806 @param logger the logger to be used. 1807 @param message the message string to log. 1808 */ 1809 #define LOG4CXX_TRACE(logger, message) do { \ 1810 if (LOG4CXX_UNLIKELY(logger->isTraceEnabled())) {\ 1811 ::log4cxx::helpers::MessageBuffer oss_; \ 1812 logger->forcedLog(::log4cxx::Level::getTrace(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1813 #else 1814 #define LOG4CXX_TRACE(logger, message) 1815 #endif 1816 1817 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 20000 1818 /** 1819 Logs a message to a specified logger with the INFO level. 1820 1821 @param logger the logger to be used. 1822 @param message the message string to log. 1823 */ 1824 #define LOG4CXX_INFO(logger, message) do { \ 1825 if (logger->isInfoEnabled()) {\ 1826 ::log4cxx::helpers::MessageBuffer oss_; \ 1827 logger->forcedLog(::log4cxx::Level::getInfo(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1828 #else 1829 #define LOG4CXX_INFO(logger, message) 1830 #endif 1831 1832 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 30000 1833 /** 1834 Logs a message to a specified logger with the WARN level. 1835 1836 @param logger the logger to be used. 1837 @param message the message string to log. 1838 */ 1839 #define LOG4CXX_WARN(logger, message) do { \ 1840 if (logger->isWarnEnabled()) {\ 1841 ::log4cxx::helpers::MessageBuffer oss_; \ 1842 logger->forcedLog(::log4cxx::Level::getWarn(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1843 #else 1844 #define LOG4CXX_WARN(logger, message) 1845 #endif 1846 1847 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 40000 1848 /** 1849 Logs a message to a specified logger with the ERROR level. 1850 1851 @param logger the logger to be used. 1852 @param message the message string to log. 1853 */ 1854 #define LOG4CXX_ERROR(logger, message) do { \ 1855 if (logger->isErrorEnabled()) {\ 1856 ::log4cxx::helpers::MessageBuffer oss_; \ 1857 logger->forcedLog(::log4cxx::Level::getError(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1858 1859 /** 1860 Logs a error if the condition is not true. 1861 1862 @param logger the logger to be used. 1863 @param condition condition 1864 @param message the message string to log. 1865 */ 1866 #define LOG4CXX_ASSERT(logger, condition, message) do { \ 1867 if (!(condition) && logger->isErrorEnabled()) {\ 1868 ::log4cxx::helpers::MessageBuffer oss_; \ 1869 logger->forcedLog(::log4cxx::Level::getError(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1870 1871 #else 1872 #define LOG4CXX_ERROR(logger, message) 1873 #define LOG4CXX_ASSERT(logger, condition, message) 1874 #endif 1875 1876 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 50000 1877 /** 1878 Logs a message to a specified logger with the FATAL level. 1879 1880 @param logger the logger to be used. 1881 @param message the message string to log. 1882 */ 1883 #define LOG4CXX_FATAL(logger, message) do { \ 1884 if (logger->isFatalEnabled()) {\ 1885 ::log4cxx::helpers::MessageBuffer oss_; \ 1886 logger->forcedLog(::log4cxx::Level::getFatal(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} while (0) 1887 #else 1888 #define LOG4CXX_FATAL(logger, message) 1889 #endif 1890 1891 /** 1892 Logs a localized message with no parameter. 1893 1894 @param logger the logger to be used. 1895 @param level the level to log. 1896 @param key the key to be searched in the resourceBundle of the logger. 1897 */ 1898 #define LOG4CXX_L7DLOG(logger, level, key) do { \ 1899 if (logger->isEnabledFor(level)) {\ 1900 logger->l7dlog(level, key, LOG4CXX_LOCATION); }} while (0) 1901 1902 /** 1903 Logs a localized message with one parameter. 1904 1905 @param logger the logger to be used. 1906 @param level the level to log. 1907 @param key the key to be searched in the resourceBundle of the logger. 1908 @param p1 the unique parameter. 1909 */ 1910 #define LOG4CXX_L7DLOG1(logger, level, key, p1) do { \ 1911 if (logger->isEnabledFor(level)) {\ 1912 logger->l7dlog(level, key, LOG4CXX_LOCATION, p1); }} while (0) 1913 1914 /** 1915 Logs a localized message with two parameters. 1916 1917 @param logger the logger to be used. 1918 @param level the level to log. 1919 @param key the key to be searched in the resourceBundle of the logger. 1920 @param p1 the first parameter. 1921 @param p2 the second parameter. 1922 */ 1923 #define LOG4CXX_L7DLOG2(logger, level, key, p1, p2) do { \ 1924 if (logger->isEnabledFor(level)) {\ 1925 logger->l7dlog(level, key, LOG4CXX_LOCATION, p1, p2); }} while (0) 1926 1927 /** 1928 Logs a localized message with three parameters. 1929 1930 @param logger the logger to be used. 1931 @param level the level to log. 1932 @param key the key to be searched in the resourceBundle of the logger. 1933 @param p1 the first parameter. 1934 @param p2 the second parameter. 1935 @param p3 the third parameter. 1936 */ 1937 #define LOG4CXX_L7DLOG3(logger, level, key, p1, p2, p3) do { \ 1938 if (logger->isEnabledFor(level)) {\ 1939 logger->l7dlog(level, key, LOG4CXX_LOCATION, p1, p2, p3); }} while (0) 1940 1941 /**@}*/ 1942 1943 #if defined(_MSC_VER) 1944 #pragma warning ( pop ) 1945 #endif 1946 1947 #include <log4cxx/spi/loggerrepository.h> 1948 1949 #endif //_LOG4CXX_LOGGER_H 1950