001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017 package org.apache.logging.log4j.spi; 018 019 import org.apache.logging.log4j.Level; 020 import org.apache.logging.log4j.Logger; 021 import org.apache.logging.log4j.Marker; 022 import org.apache.logging.log4j.MarkerManager; 023 import org.apache.logging.log4j.message.ParameterizedMessageFactory; 024 import org.apache.logging.log4j.message.Message; 025 import org.apache.logging.log4j.message.MessageFactory; 026 import org.apache.logging.log4j.status.StatusLogger; 027 028 /** 029 * Base implementation of a Logger. It is highly recommended that any Logger implementation extend this class. 030 * 031 */ 032 public abstract class AbstractLogger implements Logger { 033 034 /** 035 * Marker for flow tracing. 036 */ 037 public static final Marker FLOW_MARKER = MarkerManager.getMarker("FLOW"); 038 039 /** 040 * Marker for method entry tracing. 041 */ 042 public static final Marker ENTRY_MARKER = MarkerManager.getMarker("ENTRY", FLOW_MARKER); 043 044 /** 045 * Marker for method exit tracing. 046 */ 047 public static final Marker EXIT_MARKER = MarkerManager.getMarker("EXIT", FLOW_MARKER); 048 049 050 /** 051 * Marker for exception tracing. 052 */ 053 public static final Marker EXCEPTION_MARKER = MarkerManager.getMarker("EXCEPTION"); 054 055 /** 056 * Marker for throwing exceptions. 057 */ 058 public static final Marker THROWING_MARKER = MarkerManager.getMarker("THROWING", EXCEPTION_MARKER); 059 060 /** 061 * Marker for catching exceptions. 062 */ 063 public static final Marker CATCHING_MARKER = MarkerManager.getMarker("CATCHING", EXCEPTION_MARKER); 064 065 /** 066 * The default MessageFactory class. 067 */ 068 public static final Class<? extends MessageFactory> DEFAULT_MESSAGE_FACTORY_CLASS = 069 ParameterizedMessageFactory.class; 070 071 private static final String FQCN = AbstractLogger.class.getName(); 072 073 private static final String THROWING = "throwing"; 074 075 private static final String CATCHING = "catching"; 076 077 private final String name; 078 079 private final MessageFactory messageFactory; 080 081 /** 082 * Creates a new logger named after the class (or subclass). 083 */ 084 public AbstractLogger() { 085 this.name = getClass().getName(); 086 this.messageFactory = createDefaultMessageFactory(); 087 } 088 089 /** 090 * Creates a new named logger. 091 * 092 * @param name the logger name 093 */ 094 public AbstractLogger(final String name) { 095 this.name = name; 096 this.messageFactory = createDefaultMessageFactory(); 097 } 098 099 /** 100 * Creates a new named logger. 101 * 102 * @param name the logger name 103 * @param messageFactory the message factory, if null then use the default message factory. 104 */ 105 public AbstractLogger(final String name, final MessageFactory messageFactory) { 106 this.name = name; 107 this.messageFactory = messageFactory == null ? createDefaultMessageFactory() : messageFactory; 108 } 109 110 /** 111 * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are 112 * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default 113 * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}. 114 * 115 * @param logger 116 * The logger to check 117 * @param messageFactory 118 * The message factory to check. 119 */ 120 public static void checkMessageFactory(final Logger logger, final MessageFactory messageFactory) { 121 final String name = logger.getName(); 122 final MessageFactory loggerMessageFactory = logger.getMessageFactory(); 123 if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) { 124 StatusLogger 125 .getLogger() 126 .warn("The Logger {} was created with the message factory {} and is now requested with the " + 127 "message factory {}, which may create log events with unexpected formatting.", 128 name, loggerMessageFactory, messageFactory); 129 } else if (messageFactory == null 130 && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) { 131 StatusLogger 132 .getLogger() 133 .warn("The Logger {} was created with the message factory {} and is now requested with a null " + 134 "message factory (defaults to {}), which may create log events with unexpected formatting.", 135 name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName()); 136 } 137 } 138 139 /** 140 * Logs a Throwable that has been caught. 141 * 142 * @param level The logging Level. 143 * @param t The Throwable. 144 */ 145 @Override 146 public void catching(final Level level, final Throwable t) { 147 catching(FQCN, level, t); 148 } 149 150 /** 151 * Logs a Throwable at the {@link Level#ERROR ERROR} level.. 152 * 153 * @param t The Throwable. 154 */ 155 @Override 156 public void catching(final Throwable t) { 157 catching(FQCN, Level.ERROR, t); 158 } 159 160 /** 161 * Logs a Throwable that has been caught with location information. 162 * 163 * @param fqcn The fully qualified class name of the <b>caller</b>. 164 * @param level The logging level. 165 * @param t The Throwable. 166 */ 167 protected void catching(String fqcn, final Level level, final Throwable t) { 168 if (isEnabled(level, CATCHING_MARKER, (Object) null, null)) { 169 log(CATCHING_MARKER, fqcn, level, messageFactory.newMessage(CATCHING), t); 170 } 171 } 172 173 private MessageFactory createDefaultMessageFactory() { 174 try { 175 return DEFAULT_MESSAGE_FACTORY_CLASS.newInstance(); 176 } catch (final InstantiationException e) { 177 throw new IllegalStateException(e); 178 } catch (final IllegalAccessException e) { 179 throw new IllegalStateException(e); 180 } 181 } 182 183 /** 184 * Logs a message with the specific Marker at the DEBUG level. 185 * 186 * @param marker the marker data specific to this log statement 187 * @param msg the message string to be logged 188 */ 189 @Override 190 public void debug(final Marker marker, final Message msg) { 191 if (isEnabled(Level.DEBUG, marker, msg, null)) { 192 log(marker, FQCN, Level.DEBUG, msg, null); 193 } 194 } 195 196 /** 197 * Logs a message with the specific Marker at the DEBUG level. 198 * 199 * @param marker the marker data specific to this log statement. 200 * @param msg the message string to be logged 201 * @param t A Throwable or null. 202 */ 203 @Override 204 public void debug(final Marker marker, final Message msg, final Throwable t) { 205 if (isEnabled(Level.DEBUG, marker, msg, t)) { 206 log(marker, FQCN, Level.DEBUG, msg, t); 207 } 208 } 209 210 /** 211 * Logs a message object with the {@link Level#DEBUG DEBUG} level. 212 * 213 * @param marker the marker data specific to this log statement. 214 * @param message the message object to log. 215 */ 216 @Override 217 public void debug(final Marker marker, final Object message) { 218 if (isEnabled(Level.DEBUG, marker, message, null)) { 219 log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), null); 220 } 221 } 222 223 /** 224 * Logs a message at the {@link Level#DEBUG DEBUG} level including the 225 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 226 * 227 * @param marker the marker data specific to this log statement. 228 * @param message the message to log. 229 * @param t the exception to log, including its stack trace. 230 */ 231 @Override 232 public void debug(final Marker marker, final Object message, final Throwable t) { 233 if (isEnabled(Level.DEBUG, marker, message, t)) { 234 log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), t); 235 } 236 } 237 238 /** 239 * Logs a message object with the {@link Level#DEBUG DEBUG} level. 240 * 241 * @param marker the marker data specific to this log statement. 242 * @param message the message object to log. 243 */ 244 @Override 245 public void debug(final Marker marker, final String message) { 246 if (isEnabled(Level.DEBUG, marker, message)) { 247 log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), null); 248 } 249 } 250 251 /** 252 * Logs a message with parameters at the {@link Level#DEBUG DEBUG} level. 253 * 254 * @param marker the marker data specific to this log statement. 255 * @param message the message to log. 256 * @param params parameters to the message. 257 */ 258 @Override 259 public void debug(final Marker marker, final String message, final Object... params) { 260 if (isEnabled(Level.DEBUG, marker, message, params)) { 261 final Message msg = messageFactory.newMessage(message, params); 262 log(marker, FQCN, Level.DEBUG, msg, msg.getThrowable()); 263 } 264 } 265 266 /** 267 * Logs a message at the {@link Level#DEBUG DEBUG} level including the 268 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 269 * 270 * @param marker the marker data specific to this log statement. 271 * @param message the message to log. 272 * @param t the exception to log, including its stack trace. 273 */ 274 @Override 275 public void debug(final Marker marker, final String message, final Throwable t) { 276 if (isEnabled(Level.DEBUG, marker, message, t)) { 277 log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), t); 278 } 279 } 280 281 /** 282 * Logs a message with the specific Marker at the DEBUG level. 283 * 284 * @param msg the message string to be logged 285 */ 286 @Override 287 public void debug(final Message msg) { 288 if (isEnabled(Level.DEBUG, null, msg, null)) { 289 log(null, FQCN, Level.DEBUG, msg, null); 290 } 291 } 292 293 /** 294 * Logs a message with the specific Marker at the DEBUG level. 295 * 296 * @param msg the message string to be logged 297 * @param t A Throwable or null. 298 */ 299 @Override 300 public void debug(final Message msg, final Throwable t) { 301 if (isEnabled(Level.DEBUG, null, msg, t)) { 302 log(null, FQCN, Level.DEBUG, msg, t); 303 } 304 } 305 306 /** 307 * Logs a message object with the {@link Level#DEBUG DEBUG} level. 308 * 309 * @param message the message object to log. 310 */ 311 @Override 312 public void debug(final Object message) { 313 if (isEnabled(Level.DEBUG, null, message, null)) { 314 log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), null); 315 } 316 } 317 318 /** 319 * Logs a message at the {@link Level#DEBUG DEBUG} level including the 320 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 321 * 322 * @param message the message to log. 323 * @param t the exception to log, including its stack trace. 324 */ 325 @Override 326 public void debug(final Object message, final Throwable t) { 327 if (isEnabled(Level.DEBUG, null, message, t)) { 328 log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), t); 329 } 330 } 331 332 /** 333 * Logs a message object with the {@link Level#DEBUG DEBUG} level. 334 * 335 * @param message the message object to log. 336 */ 337 @Override 338 public void debug(final String message) { 339 if (isEnabled(Level.DEBUG, null, message)) { 340 log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), null); 341 } 342 } 343 344 /** 345 * Logs a message with parameters at the {@link Level#DEBUG DEBUG} level. 346 * 347 * @param message the message to log. 348 * @param params parameters to the message. 349 */ 350 @Override 351 public void debug(final String message, final Object... params) { 352 if (isEnabled(Level.DEBUG, null, message, params)) { 353 final Message msg = messageFactory.newMessage(message, params); 354 log(null, FQCN, Level.DEBUG, msg, msg.getThrowable()); 355 } 356 } 357 358 /** 359 * Logs a message at the {@link Level#DEBUG DEBUG} level including the 360 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 361 * 362 * @param message the message to log. 363 * @param t the exception to log, including its stack trace. 364 */ 365 @Override 366 public void debug(final String message, final Throwable t) { 367 if (isEnabled(Level.DEBUG, null, message, t)) { 368 log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), t); 369 } 370 } 371 372 /** 373 * Logs entry to a method. 374 */ 375 @Override 376 public void entry() { 377 entry(FQCN); 378 } 379 380 /** 381 * Logs entry to a method. 382 * 383 * @param params The parameters to the method. 384 */ 385 @Override 386 public void entry(final Object... params) { 387 entry(FQCN, params); 388 } 389 390 /** 391 * Logs entry to a method with location information. 392 * 393 * @param fqcn The fully qualified class name of the <b>caller</b>. 394 * @param params The parameters to the method. 395 */ 396 protected void entry(final String fqcn, final Object... params) { 397 if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) { 398 log(ENTRY_MARKER, fqcn, Level.TRACE, entryMsg(params.length, params), null); 399 } 400 } 401 402 private Message entryMsg(final int count, final Object... params) { 403 if (count == 0) { 404 return messageFactory.newMessage("entry"); 405 } 406 final StringBuilder sb = new StringBuilder("entry params("); 407 int i = 0; 408 for (final Object parm : params) { 409 if (parm != null) { 410 sb.append(parm.toString()); 411 } else { 412 sb.append("null"); 413 } 414 if (++i < params.length) { 415 sb.append(", "); 416 } 417 } 418 sb.append(")"); 419 return messageFactory.newMessage(sb.toString()); 420 } 421 422 423 /** 424 * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level. 425 * 426 * @param marker the marker data specific to this log statement 427 * @param msg the message string to be logged 428 */ 429 @Override 430 public void error(final Marker marker, final Message msg) { 431 if (isEnabled(Level.ERROR, marker, msg, null)) { 432 log(marker, FQCN, Level.ERROR, msg, null); 433 } 434 } 435 436 /** 437 * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level. 438 * 439 * @param marker the marker data specific to this log statement 440 * @param msg the message string to be logged 441 * @param t A Throwable or null. 442 */ 443 @Override 444 public void error(final Marker marker, final Message msg, final Throwable t) { 445 if (isEnabled(Level.ERROR, marker, msg, t)) { 446 log(marker, FQCN, Level.ERROR, msg, t); 447 } 448 } 449 450 /** 451 * Logs a message object with the {@link Level#ERROR ERROR} level. 452 * 453 * @param marker the marker data specific to this log statement. 454 * @param message the message object to log. 455 */ 456 @Override 457 public void error(final Marker marker, final Object message) { 458 if (isEnabled(Level.ERROR, marker, message, null)) { 459 log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), null); 460 } 461 } 462 463 /** 464 * Logs a message at the {@link Level#ERROR ERROR} level including the 465 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 466 * 467 * @param marker the marker data specific to this log statement. 468 * @param message the message object to log. 469 * @param t the exception to log, including its stack trace. 470 */ 471 @Override 472 public void error(final Marker marker, final Object message, final Throwable t) { 473 if (isEnabled(Level.ERROR, marker, message, t)) { 474 log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), t); 475 } 476 } 477 478 /** 479 * Logs a message object with the {@link Level#ERROR ERROR} level. 480 * 481 * @param marker the marker data specific to this log statement. 482 * @param message the message object to log. 483 */ 484 @Override 485 public void error(final Marker marker, final String message) { 486 if (isEnabled(Level.ERROR, marker, message)) { 487 log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), null); 488 } 489 } 490 491 /** 492 * Logs a message with parameters at the {@link Level#ERROR ERROR} level. 493 * 494 * @param marker the marker data specific to this log statement. 495 * @param message the message to log. 496 * @param params parameters to the message. 497 */ 498 @Override 499 public void error(final Marker marker, final String message, final Object... params) { 500 if (isEnabled(Level.ERROR, marker, message, params)) { 501 final Message msg = messageFactory.newMessage(message, params); 502 log(marker, FQCN, Level.ERROR, msg, msg.getThrowable()); 503 } 504 } 505 506 /** 507 * Logs a message at the {@link Level#ERROR ERROR} level including the 508 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 509 * 510 * @param marker the marker data specific to this log statement. 511 * @param message the message object to log. 512 * @param t the exception to log, including its stack trace. 513 */ 514 @Override 515 public void error(final Marker marker, final String message, final Throwable t) { 516 if (isEnabled(Level.ERROR, marker, message, t)) { 517 log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), t); 518 } 519 } 520 521 /** 522 * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level. 523 * 524 * @param msg the message string to be logged 525 */ 526 @Override 527 public void error(final Message msg) { 528 if (isEnabled(Level.ERROR, null, msg, null)) { 529 log(null, FQCN, Level.ERROR, msg, null); 530 } 531 } 532 533 /** 534 * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level. 535 * 536 * @param msg the message string to be logged 537 * @param t A Throwable or null. 538 */ 539 @Override 540 public void error(final Message msg, final Throwable t) { 541 if (isEnabled(Level.ERROR, null, msg, t)) { 542 log(null, FQCN, Level.ERROR, msg, t); 543 } 544 } 545 546 /** 547 * Logs a message object with the {@link Level#ERROR ERROR} level. 548 * 549 * @param message the message object to log. 550 */ 551 @Override 552 public void error(final Object message) { 553 if (isEnabled(Level.ERROR, null, message, null)) { 554 log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), null); 555 } 556 } 557 558 /** 559 * Logs a message at the {@link Level#ERROR ERROR} level including the 560 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 561 * 562 * @param message the message object to log. 563 * @param t the exception to log, including its stack trace. 564 */ 565 @Override 566 public void error(final Object message, final Throwable t) { 567 if (isEnabled(Level.ERROR, null, message, t)) { 568 log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), t); 569 } 570 } 571 572 /** 573 * Logs a message object with the {@link Level#ERROR ERROR} level. 574 * 575 * @param message the message object to log. 576 */ 577 @Override 578 public void error(final String message) { 579 if (isEnabled(Level.ERROR, null, message)) { 580 log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), null); 581 } 582 } 583 584 /** 585 * Logs a message with parameters at the {@link Level#ERROR ERROR} level. 586 * 587 * @param message the message to log. 588 * @param params parameters to the message. 589 */ 590 @Override 591 public void error(final String message, final Object... params) { 592 if (isEnabled(Level.ERROR, null, message, params)) { 593 final Message msg = messageFactory.newMessage(message, params); 594 log(null, FQCN, Level.ERROR, msg, msg.getThrowable()); 595 } 596 } 597 598 /** 599 * Logs a message at the {@link Level#ERROR ERROR} level including the 600 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 601 * 602 * @param message the message object to log. 603 * @param t the exception to log, including its stack trace. 604 */ 605 @Override 606 public void error(final String message, final Throwable t) { 607 if (isEnabled(Level.ERROR, null, message, t)) { 608 log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), t); 609 } 610 } 611 612 /** 613 * Logs exit from a method. 614 */ 615 @Override 616 public void exit() { 617 exit(FQCN, null); 618 } 619 620 /** 621 * Logs exiting from a method with the result. 622 * 623 * @param <R> The type of the parameter and object being returned. 624 * @param result The result being returned from the method call. 625 * @return the Throwable. 626 */ 627 @Override 628 public <R> R exit(final R result) { 629 return exit(FQCN, result); 630 } 631 632 /** 633 * Logs exiting from a method with the result and location information. 634 * 635 * @param fqcn The fully qualified class name of the <b>caller</b>. 636 * @param <R> The type of the parameter and object being returned. 637 * @param result The result being returned from the method call. 638 */ 639 protected <R> R exit(final String fqcn, final R result) { 640 if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) { 641 log(EXIT_MARKER, fqcn, Level.TRACE, toExitMsg(result), null); 642 } 643 return result; 644 } 645 646 /** 647 * Logs a message with the specific Marker at the FATAL level. 648 * 649 * @param marker the marker data specific to this log statement 650 * @param msg the message string to be logged 651 */ 652 @Override 653 public void fatal(final Marker marker, final Message msg) { 654 if (isEnabled(Level.FATAL, marker, msg, null)) { 655 log(marker, FQCN, Level.FATAL, msg, null); 656 } 657 } 658 659 /** 660 * Logs a message with the specific Marker at the FATAL level. 661 * 662 * @param marker the marker data specific to this log statement 663 * @param msg the message string to be logged 664 * @param t A Throwable or null. 665 */ 666 @Override 667 public void fatal(final Marker marker, final Message msg, final Throwable t) { 668 if (isEnabled(Level.FATAL, marker, msg, t)) { 669 log(marker, FQCN, Level.FATAL, msg, t); 670 } 671 } 672 673 /** 674 * Logs a message object with the {@link Level#FATAL FATAL} level. 675 * 676 * @param marker the marker data specific to this log statement. 677 * @param message the message object to log. 678 */ 679 @Override 680 public void fatal(final Marker marker, final Object message) { 681 if (isEnabled(Level.FATAL, marker, message, null)) { 682 log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), null); 683 } 684 } 685 686 /** 687 * Logs a message at the {@link Level#FATAL FATAL} level including the 688 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 689 * 690 * @param marker the marker data specific to this log statement. 691 * @param message the message object to log. 692 * @param t the exception to log, including its stack trace. 693 */ 694 @Override 695 public void fatal(final Marker marker, final Object message, final Throwable t) { 696 if (isEnabled(Level.FATAL, marker, message, t)) { 697 log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), t); 698 } 699 } 700 701 /** 702 * Logs a message object with the {@link Level#FATAL FATAL} level. 703 * 704 * @param marker the marker data specific to this log statement. 705 * @param message the message object to log. 706 */ 707 @Override 708 public void fatal(final Marker marker, final String message) { 709 if (isEnabled(Level.FATAL, marker, message)) { 710 log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), null); 711 } 712 } 713 714 /** 715 * Logs a message with parameters at the {@link Level#FATAL FATAL} level. 716 * 717 * @param marker the marker data specific to this log statement. 718 * @param message the message to log. 719 * @param params parameters to the message. 720 */ 721 @Override 722 public void fatal(final Marker marker, final String message, final Object... params) { 723 if (isEnabled(Level.FATAL, marker, message, params)) { 724 final Message msg = messageFactory.newMessage(message, params); 725 log(marker, FQCN, Level.FATAL, msg, msg.getThrowable()); 726 } 727 } 728 729 /** 730 * Logs a message at the {@link Level#FATAL FATAL} level including the 731 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 732 * 733 * @param marker the marker data specific to this log statement. 734 * @param message the message object to log. 735 * @param t the exception to log, including its stack trace. 736 */ 737 @Override 738 public void fatal(final Marker marker, final String message, final Throwable t) { 739 if (isEnabled(Level.FATAL, marker, message, t)) { 740 log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), t); 741 } 742 } 743 /** 744 * Logs a message with the specific Marker at the FATAL level. 745 * 746 * @param msg the message string to be logged 747 */ 748 @Override 749 public void fatal(final Message msg) { 750 if (isEnabled(Level.FATAL, null, msg, null)) { 751 log(null, FQCN, Level.FATAL, msg, null); 752 } 753 } 754 755 /** 756 * Logs a message with the specific Marker at the FATAL level. 757 * 758 * @param msg the message string to be logged 759 * @param t A Throwable or null. 760 */ 761 @Override 762 public void fatal(final Message msg, final Throwable t) { 763 if (isEnabled(Level.FATAL, null, msg, t)) { 764 log(null, FQCN, Level.FATAL, msg, t); 765 } 766 } 767 768 /** 769 * Logs a message object with the {@link Level#FATAL FATAL} level. 770 * 771 * @param message the message object to log. 772 */ 773 @Override 774 public void fatal(final Object message) { 775 if (isEnabled(Level.FATAL, null, message, null)) { 776 log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), null); 777 } 778 } 779 780 /** 781 * Logs a message at the {@link Level#FATAL FATAL} level including the 782 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 783 * 784 * @param message the message object to log. 785 * @param t the exception to log, including its stack trace. 786 */ 787 @Override 788 public void fatal(final Object message, final Throwable t) { 789 if (isEnabled(Level.FATAL, null, message, t)) { 790 log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), t); 791 } 792 } 793 794 /** 795 * Logs a message object with the {@link Level#FATAL FATAL} level. 796 * 797 * @param message the message object to log. 798 */ 799 @Override 800 public void fatal(final String message) { 801 if (isEnabled(Level.FATAL, null, message)) { 802 log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), null); 803 } 804 } 805 806 /** 807 * Logs a message with parameters at the {@link Level#FATAL FATAL} level. 808 * 809 * @param message the message to log. 810 * @param params parameters to the message. 811 */ 812 @Override 813 public void fatal(final String message, final Object... params) { 814 if (isEnabled(Level.FATAL, null, message, params)) { 815 final Message msg = messageFactory.newMessage(message, params); 816 log(null, FQCN, Level.FATAL, msg, msg.getThrowable()); 817 } 818 } 819 820 /** 821 * Logs a message at the {@link Level#FATAL FATAL} level including the 822 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 823 * 824 * @param message the message object to log. 825 * @param t the exception to log, including its stack trace. 826 */ 827 @Override 828 public void fatal(final String message, final Throwable t) { 829 if (isEnabled(Level.FATAL, null, message, t)) { 830 log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), t); 831 } 832 } 833 834 /** 835 * Gets the message factory. 836 * 837 * @return the message factory. 838 */ 839 @Override 840 public MessageFactory getMessageFactory() { 841 return messageFactory; 842 } 843 844 /* (non-Javadoc) 845 * @see org.apache.logging.log4j.Logger#getName() 846 */ 847 @Override 848 public String getName() { 849 return name; 850 } 851 852 /** 853 * Logs a message with the specific Marker at the INFO level. 854 * 855 * @param marker the marker data specific to this log statement 856 * @param msg the message string to be logged 857 */ 858 @Override 859 public void info(final Marker marker, final Message msg) { 860 if (isEnabled(Level.INFO, marker, msg, null)) { 861 log(marker, FQCN, Level.INFO, msg, null); 862 } 863 } 864 865 /** 866 * Logs a message with the specific Marker at the INFO level. 867 * 868 * @param marker the marker data specific to this log statement 869 * @param msg the message string to be logged 870 * @param t A Throwable or null. 871 */ 872 @Override 873 public void info(final Marker marker, final Message msg, final Throwable t) { 874 if (isEnabled(Level.INFO, marker, msg, t)) { 875 log(marker, FQCN, Level.INFO, msg, t); 876 } 877 } 878 879 /** 880 * Logs a message object with the {@link Level#INFO INFO} level. 881 * 882 * @param marker the marker data specific to this log statement. 883 * @param message the message object to log. 884 */ 885 @Override 886 public void info(final Marker marker, final Object message) { 887 if (isEnabled(Level.INFO, marker, message, null)) { 888 log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), null); 889 } 890 } 891 892 /** 893 * Logs a message at the {@link Level#INFO INFO} level including the 894 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 895 * 896 * @param marker the marker data specific to this log statement. 897 * @param message the message object to log. 898 * @param t the exception to log, including its stack trace. 899 */ 900 @Override 901 public void info(final Marker marker, final Object message, final Throwable t) { 902 if (isEnabled(Level.INFO, marker, message, t)) { 903 log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), t); 904 } 905 } 906 907 /** 908 * Logs a message object with the {@link Level#INFO INFO} level. 909 * 910 * @param marker the marker data specific to this log statement. 911 * @param message the message object to log. 912 */ 913 @Override 914 public void info(final Marker marker, final String message) { 915 if (isEnabled(Level.INFO, marker, message)) { 916 log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), null); 917 } 918 } 919 920 /** 921 * Logs a message with parameters at the {@link Level#INFO INFO} level. 922 * 923 * @param marker the marker data specific to this log statement. 924 * @param message the message to log. 925 * @param params parameters to the message. 926 */ 927 @Override 928 public void info(final Marker marker, final String message, final Object... params) { 929 if (isEnabled(Level.INFO, marker, message, params)) { 930 final Message msg = messageFactory.newMessage(message, params); 931 log(marker, FQCN, Level.INFO, msg, msg.getThrowable()); 932 } 933 } 934 935 /** 936 * Logs a message at the {@link Level#INFO INFO} level including the 937 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 938 * 939 * @param marker the marker data specific to this log statement. 940 * @param message the message object to log. 941 * @param t the exception to log, including its stack trace. 942 */ 943 @Override 944 public void info(final Marker marker, final String message, final Throwable t) { 945 if (isEnabled(Level.INFO, marker, message, t)) { 946 log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), t); 947 } 948 } 949 950 /** 951 * Logs a message with the specific Marker at the TRACE level. 952 * 953 * @param msg the message string to be logged 954 */ 955 @Override 956 public void info(final Message msg) { 957 if (isEnabled(Level.INFO, null, msg, null)) { 958 log(null, FQCN, Level.INFO, msg, null); 959 } 960 } 961 962 /** 963 * Logs a message with the specific Marker at the INFO level. 964 * 965 * @param msg the message string to be logged 966 * @param t A Throwable or null. 967 */ 968 @Override 969 public void info(final Message msg, final Throwable t) { 970 if (isEnabled(Level.INFO, null, msg, t)) { 971 log(null, FQCN, Level.INFO, msg, t); 972 } 973 } 974 975 /** 976 * Logs a message object with the {@link Level#INFO INFO} level. 977 * 978 * @param message the message object to log. 979 */ 980 @Override 981 public void info(final Object message) { 982 if (isEnabled(Level.INFO, null, message, null)) { 983 log(null, FQCN, Level.INFO, messageFactory.newMessage(message), null); 984 } 985 } 986 987 988 /** 989 * Logs a message at the {@link Level#INFO INFO} level including the 990 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 991 * 992 * @param message the message object to log. 993 * @param t the exception to log, including its stack trace. 994 */ 995 @Override 996 public void info(final Object message, final Throwable t) { 997 if (isEnabled(Level.INFO, null, message, t)) { 998 log(null, FQCN, Level.INFO, messageFactory.newMessage(message), t); 999 } 1000 } 1001 1002 /** 1003 * Logs a message object with the {@link Level#INFO INFO} level. 1004 * 1005 * @param message the message object to log. 1006 */ 1007 @Override 1008 public void info(final String message) { 1009 if (isEnabled(Level.INFO, null, message)) { 1010 log(null, FQCN, Level.INFO, messageFactory.newMessage(message), null); 1011 } 1012 } 1013 1014 /** 1015 * Logs a message with parameters at the {@link Level#INFO INFO} level. 1016 * 1017 * @param message the message to log. 1018 * @param params parameters to the message. 1019 */ 1020 @Override 1021 public void info(final String message, final Object... params) { 1022 if (isEnabled(Level.INFO, null, message, params)) { 1023 final Message msg = messageFactory.newMessage(message, params); 1024 log(null, FQCN, Level.INFO, msg, msg.getThrowable()); 1025 } 1026 } 1027 1028 /** 1029 * Logs a message at the {@link Level#INFO INFO} level including the 1030 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1031 * 1032 * @param message the message object to log. 1033 * @param t the exception to log, including its stack trace. 1034 */ 1035 @Override 1036 public void info(final String message, final Throwable t) { 1037 if (isEnabled(Level.INFO, null, message, t)) { 1038 log(null, FQCN, Level.INFO, messageFactory.newMessage(message), t); 1039 } 1040 } 1041 1042 /** 1043 * Checks whether this Logger is enabled for the DEBUG Level. 1044 * 1045 * @return boolean - {@code true} if this Logger is enabled for level 1046 * DEBUG, {@code false} otherwise. 1047 */ 1048 @Override 1049 public boolean isDebugEnabled() { 1050 return isEnabled(Level.DEBUG, null, null); 1051 } 1052 1053 /** 1054 * Checks whether this Logger is enabled for the DEBUG Level. 1055 * 1056 * @param marker The marker data. 1057 * @return boolean - {@code true} if this Logger is enabled for level 1058 * DEBUG, {@code false} otherwise. 1059 */ 1060 @Override 1061 public boolean isDebugEnabled(final Marker marker) { 1062 return isEnabled(Level.DEBUG, marker, (Object) null, null); 1063 } 1064 1065 /** 1066 * Checks whether this Logger is enabled for the the given Level. 1067 * <p> 1068 * Note that passing in {@link Level#OFF OFF} always returns {@code true}. 1069 * </p> 1070 * @param level the level to check 1071 * @return boolean - {@code true} if this Logger is enabled for level, {@code false} otherwise. 1072 */ 1073 @Override 1074 public boolean isEnabled(final Level level) { 1075 return isEnabled(level, null, (Object) null, null); 1076 } 1077 1078 /** 1079 * Determine if logging is enabled. 1080 * @param level The logging Level to check. 1081 * @param marker A Marker or null. 1082 * @param data The Message. 1083 * @param t A Throwable. 1084 * @return True if logging is enabled, false otherwise. 1085 */ 1086 protected abstract boolean isEnabled(Level level, Marker marker, Message data, Throwable t); 1087 1088 /** 1089 * Determine if logging is enabled. 1090 * @param level The logging Level to check. 1091 * @param marker A Marker or null. 1092 * @param data The message. 1093 * @param t A Throwable. 1094 * @return True if logging is enabled, false otherwise. 1095 */ 1096 protected abstract boolean isEnabled(Level level, Marker marker, Object data, Throwable t); 1097 1098 /** 1099 * Determine if logging is enabled. 1100 * @param level The logging Level to check. 1101 * @param marker A Marker or null. 1102 * @param data The message. 1103 * @return True if logging is enabled, false otherwise. 1104 */ 1105 protected abstract boolean isEnabled(Level level, Marker marker, String data); 1106 1107 /** 1108 * Determine if logging is enabled. 1109 * @param level The logging Level to check. 1110 * @param marker A Marker or null. 1111 * @param data The message. 1112 * @param p1 The parameters. 1113 * @return True if logging is enabled, false otherwise. 1114 */ 1115 protected abstract boolean isEnabled(Level level, Marker marker, String data, Object... p1); 1116 1117 /** 1118 * Determine if logging is enabled. 1119 * @param level The logging Level to check. 1120 * @param marker A Marker or null. 1121 * @param data The message. 1122 * @param t A Throwable. 1123 * @return True if logging is enabled, false otherwise. 1124 */ 1125 protected abstract boolean isEnabled(Level level, Marker marker, String data, Throwable t); 1126 1127 /** 1128 * Checks whether this Logger is enabled for the {@link Level#ERROR ERROR} Level. 1129 * 1130 * @return boolean - {@code true} if this Logger is enabled for level 1131 * {@link Level#ERROR ERROR}, {@code false} otherwise. 1132 */ 1133 @Override 1134 public boolean isErrorEnabled() { 1135 return isEnabled(Level.ERROR, null, (Object) null, null); 1136 } 1137 1138 /** 1139 * Checks whether this Logger is enabled for the {@link Level#ERROR ERROR} Level. 1140 * 1141 * @param marker The marker data. 1142 * @return boolean - {@code true} if this Logger is enabled for level 1143 * {@link Level#ERROR ERROR}, {@code false} otherwise. 1144 */ 1145 @Override 1146 public boolean isErrorEnabled(final Marker marker) { 1147 return isEnabled(Level.ERROR, marker, (Object) null, null); 1148 } 1149 1150 /** 1151 * Checks whether this Logger is enabled for the FATAL Level. 1152 * 1153 * @return boolean - {@code true} if this Logger is enabled for level 1154 * FATAL, {@code false} otherwise. 1155 */ 1156 @Override 1157 public boolean isFatalEnabled() { 1158 return isEnabled(Level.FATAL, null, (Object) null, null); 1159 } 1160 1161 /** 1162 * Checks whether this Logger is enabled for the FATAL Level. 1163 * 1164 * @param marker The marker data. 1165 * @return boolean - {@code true} if this Logger is enabled for level 1166 * FATAL, {@code false} otherwise. 1167 */ 1168 @Override 1169 public boolean isFatalEnabled(final Marker marker) { 1170 return isEnabled(Level.FATAL, marker, (Object) null, null); 1171 } 1172 1173 /** 1174 * Checks whether this Logger is enabled for the INFO Level. 1175 * 1176 * @return boolean - {@code true} if this Logger is enabled for level 1177 * INFO, {@code false} otherwise. 1178 */ 1179 @Override 1180 public boolean isInfoEnabled() { 1181 return isEnabled(Level.INFO, null, (Object) null, null); 1182 } 1183 1184 /** 1185 * Checks whether this Logger is enabled for the INFO Level. 1186 * @param marker The marker data. 1187 * @return boolean - {@code true} if this Logger is enabled for level 1188 * INFO, {@code false} otherwise. 1189 */ 1190 @Override 1191 public boolean isInfoEnabled(final Marker marker) { 1192 return isEnabled(Level.INFO, marker, (Object) null, null); 1193 } 1194 1195 /** 1196 * Checks whether this Logger is enabled for the TRACE Level. 1197 * 1198 * @return boolean - {@code true} if this Logger is enabled for level 1199 * TRACE, {@code false} otherwise. 1200 */ 1201 @Override 1202 public boolean isTraceEnabled() { 1203 return isEnabled(Level.TRACE, null, (Object) null, null); 1204 } 1205 1206 /** 1207 * Checks whether this Logger is enabled for the TRACE Level. 1208 * 1209 * @param marker The marker data. 1210 * @return boolean - {@code true} if this Logger is enabled for level 1211 * TRACE, {@code false} otherwise. 1212 */ 1213 @Override 1214 public boolean isTraceEnabled(final Marker marker) { 1215 return isEnabled(Level.TRACE, marker, (Object) null, null); 1216 } 1217 1218 1219 /** 1220 * Checks whether this Logger is enabled for the WARN Level. 1221 * 1222 * @return boolean - {@code true} if this Logger is enabled for level 1223 * WARN, {@code false} otherwise. 1224 */ 1225 @Override 1226 public boolean isWarnEnabled() { 1227 return isEnabled(Level.WARN, null, (Object) null, null); 1228 } 1229 1230 /** 1231 * Checks whether this Logger is enabled for the WARN Level. 1232 * 1233 * @param marker The marker data. 1234 * @return boolean - {@code true} if this Logger is enabled for level 1235 * WARN, {@code false} otherwise. 1236 */ 1237 @Override 1238 public boolean isWarnEnabled(final Marker marker) { 1239 return isEnabled(Level.WARN, marker, (Object) null, null); 1240 } 1241 1242 @Override 1243 public boolean isEnabled(final Level level, final Marker marker) { 1244 return isEnabled(level, marker, (Object) null, null); 1245 } 1246 1247 /** 1248 * Logs a message with the specific Marker at the given level. 1249 * 1250 * @param level the logging level 1251 * @param marker the marker data specific to this log statement 1252 * @param msg the message string to be logged 1253 */ 1254 @Override 1255 public void log(final Level level, final Marker marker, final Message msg) { 1256 if (isEnabled(level, marker, msg, null)) { 1257 log(marker, FQCN, level, msg, null); 1258 } 1259 } 1260 1261 /** 1262 * Logs a message with the specific Marker at the given level. 1263 * 1264 * @param level the logging level 1265 * @param marker the marker data specific to this log statement. 1266 * @param msg the message string to be logged 1267 * @param t A Throwable or null. 1268 */ 1269 @Override 1270 public void log(final Level level, final Marker marker, final Message msg, final Throwable t) { 1271 if (isEnabled(level, marker, msg, t)) { 1272 log(marker, FQCN, level, msg, t); 1273 } 1274 } 1275 1276 /** 1277 * Logs a message object with the given level. 1278 * 1279 * @param level the logging level 1280 * @param marker the marker data specific to this log statement. 1281 * @param message the message object to log. 1282 */ 1283 @Override 1284 public void log(final Level level, final Marker marker, final Object message) { 1285 if (isEnabled(level, marker, message, null)) { 1286 log(marker, FQCN, level, messageFactory.newMessage(message), null); 1287 } 1288 } 1289 1290 /** 1291 * Logs a message at the given level including the 1292 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1293 * 1294 * @param level the logging level 1295 * @param marker the marker data specific to this log statement. 1296 * @param message the message to log. 1297 * @param t the exception to log, including its stack trace. 1298 */ 1299 @Override 1300 public void log(final Level level, final Marker marker, final Object message, final Throwable t) { 1301 if (isEnabled(level, marker, message, t)) { 1302 log(marker, FQCN, level, messageFactory.newMessage(message), t); 1303 } 1304 } 1305 1306 /** 1307 * Logs a message object with the given level. 1308 * 1309 * @param level the logging level 1310 * @param marker the marker data specific to this log statement. 1311 * @param message the message object to log. 1312 */ 1313 @Override 1314 public void log(final Level level, final Marker marker, final String message) { 1315 if (isEnabled(level, marker, message)) { 1316 log(marker, FQCN, level, messageFactory.newMessage(message), null); 1317 } 1318 } 1319 1320 /** 1321 * Logs a message with parameters at the given level. 1322 * 1323 * @param level the logging level 1324 * @param marker the marker data specific to this log statement. 1325 * @param message the message to log. 1326 * @param params parameters to the message. 1327 */ 1328 @Override 1329 public void log(final Level level, final Marker marker, final String message, final Object... params) { 1330 if (isEnabled(level, marker, message, params)) { 1331 final Message msg = messageFactory.newMessage(message, params); 1332 log(marker, FQCN, level, msg, msg.getThrowable()); 1333 } 1334 } 1335 1336 /** 1337 * Logs a message at the given level including the 1338 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1339 * 1340 * @param level the logging level 1341 * @param marker the marker data specific to this log statement. 1342 * @param message the message to log. 1343 * @param t the exception to log, including its stack trace. 1344 */ 1345 @Override 1346 public void log(final Level level, final Marker marker, final String message, final Throwable t) { 1347 if (isEnabled(level, marker, message, t)) { 1348 log(marker, FQCN, level, messageFactory.newMessage(message), t); 1349 } 1350 } 1351 1352 /** 1353 * Logs a message with the specific Marker at the given level. 1354 * 1355 * @param level the logging level 1356 * @param msg the message string to be logged 1357 */ 1358 @Override 1359 public void log(final Level level, final Message msg) { 1360 if (isEnabled(level, null, msg, null)) { 1361 log(null, FQCN, level, msg, null); 1362 } 1363 } 1364 1365 /** 1366 * Logs a message with the specific Marker at the given level. 1367 * 1368 * @param level the logging level 1369 * @param msg the message string to be logged 1370 * @param t A Throwable or null. 1371 */ 1372 @Override 1373 public void log(final Level level, final Message msg, final Throwable t) { 1374 if (isEnabled(level, null, msg, t)) { 1375 log(null, FQCN, level, msg, t); 1376 } 1377 } 1378 1379 /** 1380 * Logs a message object with the given level. 1381 * 1382 * @param level the logging level 1383 * @param message the message object to log. 1384 */ 1385 @Override 1386 public void log(final Level level, final Object message) { 1387 if (isEnabled(level, null, message, null)) { 1388 log(null, FQCN, level, messageFactory.newMessage(message), null); 1389 } 1390 } 1391 1392 /** 1393 * Logs a message at the given level including the 1394 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1395 * 1396 * @param level the logging level 1397 * @param message the message to log. 1398 * @param t the exception to log, including its stack trace. 1399 */ 1400 @Override 1401 public void log(final Level level, final Object message, final Throwable t) { 1402 if (isEnabled(level, null, message, t)) { 1403 log(null, FQCN, level, messageFactory.newMessage(message), t); 1404 } 1405 } 1406 1407 /** 1408 * Logs a message object with the given level. 1409 * 1410 * @param level the logging level 1411 * @param message the message object to log. 1412 */ 1413 @Override 1414 public void log(final Level level, final String message) { 1415 if (isEnabled(level, null, message)) { 1416 log(null, FQCN, level, messageFactory.newMessage(message), null); 1417 } 1418 } 1419 1420 /** 1421 * Logs a message with parameters at the given level. 1422 * 1423 * @param level the logging level 1424 * @param message the message to log. 1425 * @param params parameters to the message. 1426 */ 1427 @Override 1428 public void log(final Level level, final String message, final Object... params) { 1429 if (isEnabled(level, null, message, params)) { 1430 final Message msg = messageFactory.newMessage(message, params); 1431 log(null, FQCN, level, msg, msg.getThrowable()); 1432 } 1433 } 1434 1435 1436 /** 1437 * Logs a message at the given level including the 1438 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1439 * 1440 * @param level the logging level 1441 * @param message the message to log. 1442 * @param t the exception to log, including its stack trace. 1443 */ 1444 @Override 1445 public void log(final Level level, final String message, final Throwable t) { 1446 if (isEnabled(level, null, message, t)) { 1447 log(null, FQCN, level, messageFactory.newMessage(message), t); 1448 } 1449 } 1450 1451 /** 1452 * Logs a message with location information. 1453 * 1454 * @param marker The Marker 1455 * @param fqcn The fully qualified class name of the <b>caller</b> 1456 * @param level The logging level 1457 * @param data The Message. 1458 * @param t A Throwable or null. 1459 */ 1460 protected abstract void log(Marker marker, String fqcn, Level level, Message data, Throwable t); 1461 1462 /** 1463 * Logs a Throwable to be thrown. 1464 * 1465 * @param <T> the type of the Throwable. 1466 * @param level The logging Level. 1467 * @param t The Throwable. 1468 * @return the Throwable. 1469 */ 1470 @Override 1471 public <T extends Throwable> T throwing(final Level level, final T t) { 1472 return throwing(FQCN, level, t); 1473 } 1474 1475 /** 1476 * Logs a Throwable to be thrown. 1477 * 1478 * @param <T> the type of the Throwable. 1479 * @param t The Throwable. 1480 * @return the Throwable. 1481 */ 1482 @Override 1483 public <T extends Throwable> T throwing(final T t) { 1484 return throwing(FQCN, Level.ERROR, t); 1485 } 1486 1487 /** 1488 * Logs a Throwable to be thrown with location information. 1489 * 1490 * @param fqcn The fully qualified class name of the <b>caller</b>. 1491 * @param <T> the type of the Throwable. 1492 * @param level The logging Level. 1493 * @param t The Throwable. 1494 * @return the Throwable. 1495 */ 1496 protected <T extends Throwable> T throwing(String fqcn, final Level level, final T t) { 1497 if (isEnabled(level, THROWING_MARKER, (Object) null, null)) { 1498 log(THROWING_MARKER, fqcn, level, messageFactory.newMessage(THROWING), t); 1499 } 1500 return t; 1501 } 1502 1503 private Message toExitMsg(final Object result) { 1504 if (result == null) { 1505 return messageFactory.newMessage("exit"); 1506 } 1507 return messageFactory.newMessage("exit with(" + result + ")"); 1508 } 1509 1510 /** 1511 * Returns a String representation of this instance in the form {@code "name"}. 1512 * @return A String describing this Logger instance. 1513 */ 1514 @Override 1515 public String toString() { 1516 return name; 1517 } 1518 1519 /** 1520 * Logs a message with the specific Marker at the TRACE level. 1521 * 1522 * @param marker the marker data specific to this log statement. 1523 * @param msg the message string to be logged 1524 */ 1525 @Override 1526 public void trace(final Marker marker, final Message msg) { 1527 if (isEnabled(Level.TRACE, marker, msg, null)) { 1528 log(marker, FQCN, Level.TRACE, msg, null); 1529 } 1530 } 1531 1532 1533 /** 1534 * Logs a message with the specific Marker at the TRACE level. 1535 * 1536 * @param marker the marker data specific to this log statement. 1537 * @param msg the message string to be logged 1538 * @param t A Throwable or null. 1539 */ 1540 @Override 1541 public void trace(final Marker marker, final Message msg, final Throwable t) { 1542 if (isEnabled(Level.TRACE, marker, msg, t)) { 1543 log(marker, FQCN, Level.TRACE, msg, t); 1544 } 1545 } 1546 1547 /** 1548 * Logs a message object with the {@link Level#TRACE TRACE} level. 1549 * 1550 * @param marker the marker data specific to this log statement. 1551 * @param message the message object to log. 1552 */ 1553 @Override 1554 public void trace(final Marker marker, final Object message) { 1555 if (isEnabled(Level.TRACE, marker, message, null)) { 1556 log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), null); 1557 } 1558 } 1559 1560 /** 1561 * Logs a message at the {@link Level#TRACE TRACE} level including the 1562 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1563 * <p/> 1564 * <p> 1565 * See {@link #debug(String)} form for more detailed information. 1566 * </p> 1567 * 1568 * @param marker the marker data specific to this log statement. 1569 * @param message the message object to log. 1570 * @param t the exception to log, including its stack trace. 1571 */ 1572 @Override 1573 public void trace(final Marker marker, final Object message, final Throwable t) { 1574 if (isEnabled(Level.TRACE, marker, message, t)) { 1575 log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), t); 1576 } 1577 } 1578 1579 /** 1580 * Logs a message object with the {@link Level#TRACE TRACE} level. 1581 * 1582 * @param marker the marker data specific to this log statement. 1583 * @param message the message object to log. 1584 */ 1585 @Override 1586 public void trace(final Marker marker, final String message) { 1587 if (isEnabled(Level.TRACE, marker, message)) { 1588 log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), null); 1589 } 1590 } 1591 1592 /** 1593 * Logs a message with parameters at the {@link Level#TRACE TRACE} level. 1594 * 1595 * @param marker the marker data specific to this log statement. 1596 * @param message the message to log. 1597 * @param params parameters to the message. 1598 */ 1599 @Override 1600 public void trace(final Marker marker, final String message, final Object... params) { 1601 if (isEnabled(Level.TRACE, marker, message, params)) { 1602 final Message msg = messageFactory.newMessage(message, params); 1603 log(marker, FQCN, Level.TRACE, msg, msg.getThrowable()); 1604 } 1605 } 1606 1607 /** 1608 * Logs a message at the {@link Level#TRACE TRACE} level including the 1609 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1610 * <p/> 1611 * <p> 1612 * See {@link #debug(String)} form for more detailed information. 1613 * </p> 1614 * 1615 * @param marker the marker data specific to this log statement. 1616 * @param message the message object to log. 1617 * @param t the exception to log, including its stack trace. 1618 */ 1619 @Override 1620 public void trace(final Marker marker, final String message, final Throwable t) { 1621 if (isEnabled(Level.TRACE, marker, message, t)) { 1622 log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), t); 1623 } 1624 } 1625 1626 /** 1627 * Logs a message with the specific Marker at the TRACE level. 1628 * 1629 * @param msg the message string to be logged 1630 */ 1631 @Override 1632 public void trace(final Message msg) { 1633 if (isEnabled(Level.TRACE, null, msg, null)) { 1634 log(null, FQCN, Level.TRACE, msg, null); 1635 } 1636 } 1637 1638 /** 1639 * Logs a message with the specific Marker at the TRACE level. 1640 * 1641 * @param msg the message string to be logged 1642 * @param t A Throwable or null. 1643 */ 1644 @Override 1645 public void trace(final Message msg, final Throwable t) { 1646 if (isEnabled(Level.TRACE, null, msg, t)) { 1647 log(null, FQCN, Level.TRACE, msg, t); 1648 } 1649 } 1650 1651 /** 1652 * Logs a message object with the {@link Level#TRACE TRACE} level. 1653 * 1654 * @param message the message object to log. 1655 */ 1656 @Override 1657 public void trace(final Object message) { 1658 if (isEnabled(Level.TRACE, null, message, null)) { 1659 log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), null); 1660 } 1661 } 1662 1663 /** 1664 * Logs a message at the {@link Level#TRACE TRACE} level including the 1665 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1666 * <p/> 1667 * <p> 1668 * See {@link #debug(String)} form for more detailed information. 1669 * </p> 1670 * 1671 * @param message the message object to log. 1672 * @param t the exception to log, including its stack trace. 1673 */ 1674 @Override 1675 public void trace(final Object message, final Throwable t) { 1676 if (isEnabled(Level.TRACE, null, message, t)) { 1677 log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), t); 1678 } 1679 } 1680 1681 /** 1682 * Logs a message object with the {@link Level#TRACE TRACE} level. 1683 * 1684 * @param message the message object to log. 1685 */ 1686 @Override 1687 public void trace(final String message) { 1688 if (isEnabled(Level.TRACE, null, message)) { 1689 log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), null); 1690 } 1691 } 1692 1693 /** 1694 * Logs a message with parameters at the {@link Level#TRACE TRACE} level. 1695 * 1696 * @param message the message to log. 1697 * @param params parameters to the message. 1698 */ 1699 @Override 1700 public void trace(final String message, final Object... params) { 1701 if (isEnabled(Level.TRACE, null, message, params)) { 1702 final Message msg = messageFactory.newMessage(message, params); 1703 log(null, FQCN, Level.TRACE, msg, msg.getThrowable()); 1704 } 1705 } 1706 1707 /** 1708 * Logs a message at the {@link Level#TRACE TRACE} level including the 1709 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1710 * <p/> 1711 * <p> 1712 * See {@link #debug(String)} form for more detailed information. 1713 * </p> 1714 * 1715 * @param message the message object to log. 1716 * @param t the exception to log, including its stack trace. 1717 */ 1718 @Override 1719 public void trace(final String message, final Throwable t) { 1720 if (isEnabled(Level.TRACE, null, message, t)) { 1721 log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), t); 1722 } 1723 } 1724 1725 /** 1726 * Logs a message with the specific Marker at the WARN level. 1727 * 1728 * @param marker the marker data specific to this log statement 1729 * @param msg the message string to be logged 1730 */ 1731 @Override 1732 public void warn(final Marker marker, final Message msg) { 1733 if (isEnabled(Level.WARN, marker, msg, null)) { 1734 log(marker, FQCN, Level.WARN, msg, null); 1735 } 1736 } 1737 1738 /** 1739 * Logs a message with the specific Marker at the WARN level. 1740 * 1741 * @param marker the marker data specific to this log statement 1742 * @param msg the message string to be logged 1743 * @param t A Throwable or null. 1744 */ 1745 @Override 1746 public void warn(final Marker marker, final Message msg, final Throwable t) { 1747 if (isEnabled(Level.WARN, marker, msg, t)) { 1748 log(marker, FQCN, Level.WARN, msg, t); 1749 } 1750 } 1751 1752 /** 1753 * Logs a message object with the {@link Level#WARN WARN} level. 1754 * 1755 * @param marker the marker data specific to this log statement. 1756 * @param message the message object to log. 1757 */ 1758 @Override 1759 public void warn(final Marker marker, final Object message) { 1760 if (isEnabled(Level.WARN, marker, message, null)) { 1761 log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), null); 1762 } 1763 } 1764 1765 /* 1766 * Instead of one single method with Object... declared the following methods explicitly specify 1767 * parameters because they perform dramatically better than having the JVM convert them to an 1768 * array. 1769 */ 1770 1771 /** 1772 * Logs a message at the {@link Level#WARN WARN} level including the 1773 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1774 * 1775 * @param marker the marker data specific to this log statement. 1776 * @param message the message object to log. 1777 * @param t the exception to log, including its stack trace. 1778 */ 1779 @Override 1780 public void warn(final Marker marker, final Object message, final Throwable t) { 1781 if (isEnabled(Level.WARN, marker, message, t)) { 1782 log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), t); 1783 } 1784 } 1785 1786 /** 1787 * Logs a message object with the {@link Level#WARN WARN} level. 1788 * 1789 * @param marker the marker data specific to this log statement. 1790 * @param message the message object to log. 1791 */ 1792 @Override 1793 public void warn(final Marker marker, final String message) { 1794 if (isEnabled(Level.WARN, marker, message)) { 1795 log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), null); 1796 } 1797 } 1798 1799 /** 1800 * Logs a message with parameters at the {@link Level#WARN WARN} level. 1801 * 1802 * @param marker the marker data specific to this log statement. 1803 * @param message the message to log. 1804 * @param params parameters to the message. 1805 */ 1806 @Override 1807 public void warn(final Marker marker, final String message, final Object... params) { 1808 if (isEnabled(Level.WARN, marker, message, params)) { 1809 final Message msg = messageFactory.newMessage(message, params); 1810 log(marker, FQCN, Level.WARN, msg, msg.getThrowable()); 1811 } 1812 } 1813 1814 /** 1815 * Logs a message at the {@link Level#WARN WARN} level including the 1816 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1817 * 1818 * @param marker the marker data specific to this log statement. 1819 * @param message the message object to log. 1820 * @param t the exception to log, including its stack trace. 1821 */ 1822 @Override 1823 public void warn(final Marker marker, final String message, final Throwable t) { 1824 if (isEnabled(Level.WARN, marker, message, t)) { 1825 log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), t); 1826 } 1827 } 1828 1829 /** 1830 * Logs a message with the specific Marker at the WARN level. 1831 * 1832 * @param msg the message string to be logged 1833 */ 1834 @Override 1835 public void warn(final Message msg) { 1836 if (isEnabled(Level.WARN, null, msg, null)) { 1837 log(null, FQCN, Level.WARN, msg, null); 1838 } 1839 } 1840 1841 /** 1842 * Logs a message with the specific Marker at the WARN level. 1843 * 1844 * @param msg the message string to be logged 1845 * @param t A Throwable or null. 1846 */ 1847 @Override 1848 public void warn(final Message msg, final Throwable t) { 1849 if (isEnabled(Level.WARN, null, msg, t)) { 1850 log(null, FQCN, Level.WARN, msg, t); 1851 } 1852 } 1853 1854 /** 1855 * Logs a message object with the {@link Level#WARN WARN} level. 1856 * 1857 * @param message the message object to log. 1858 */ 1859 @Override 1860 public void warn(final Object message) { 1861 if (isEnabled(Level.WARN, null, message, null)) { 1862 log(null, FQCN, Level.WARN, messageFactory.newMessage(message), null); 1863 } 1864 } 1865 1866 /** 1867 * Logs a message at the {@link Level#WARN WARN} level including the 1868 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1869 * 1870 * @param message the message object to log. 1871 * @param t the exception to log, including its stack trace. 1872 */ 1873 @Override 1874 public void warn(final Object message, final Throwable t) { 1875 if (isEnabled(Level.WARN, null, message, t)) { 1876 log(null, FQCN, Level.WARN, messageFactory.newMessage(message), t); 1877 } 1878 } 1879 1880 /** 1881 * Logs a message object with the {@link Level#WARN WARN} level. 1882 * 1883 * @param message the message object to log. 1884 */ 1885 @Override 1886 public void warn(final String message) { 1887 if (isEnabled(Level.WARN, null, message)) { 1888 log(null, FQCN, Level.WARN, messageFactory.newMessage(message), null); 1889 } 1890 } 1891 1892 /** 1893 * Logs a message with parameters at the {@link Level#WARN WARN} level. 1894 * 1895 * @param message the message to log. 1896 * @param params parameters to the message. 1897 */ 1898 @Override 1899 public void warn(final String message, final Object... params) { 1900 if (isEnabled(Level.WARN, null, message, params)) { 1901 final Message msg = messageFactory.newMessage(message, params); 1902 log(null, FQCN, Level.WARN, msg, msg.getThrowable()); 1903 } 1904 } 1905 1906 /** 1907 * Logs a message at the {@link Level#WARN WARN} level including the 1908 * stack trace of the {@link Throwable} <code>t</code> passed as parameter. 1909 * 1910 * @param message the message object to log. 1911 * @param t the exception to log, including its stack trace. 1912 */ 1913 @Override 1914 public void warn(final String message, final Throwable t) { 1915 if (isEnabled(Level.WARN, null, message, t)) { 1916 log(null, FQCN, Level.WARN, messageFactory.newMessage(message), t); 1917 } 1918 } 1919 1920 }