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