View Javadoc

1   package com.atlassian.scheduler.core.util;
2   
3   import org.slf4j.Logger;
4   
5   /**
6    * Log a warning, optionally including a full stack trace if the logger's {@code DEBUG} level is enabled.
7    */
8   public class LogWarn {
9       // Static-only
10      private LogWarn() {
11      }
12  
13      /**
14       * Log a warning, optionally including a full stack trace if the logger's {@code DEBUG} level is enabled.
15       * <p>
16       * That is, if {@code DEBUG} is enabled, the logger gets the warning with a full stack trace included.
17       * Otherwise, the exception's {@code .toString()} is appended to the message, keeping it comparatively brief.
18       * </p>
19       *
20       * @param log     the logger to receive the warning message
21       * @param message the message to be logged
22       * @param cause   the exception that triggered the warning
23       */
24      public static void logWarn(Logger log, String message, Throwable cause) {
25          if (log.isDebugEnabled()) {
26              log.warn(message, cause);
27          } else {
28              log.warn(message + ": " + cause);
29          }
30      }
31  }