⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log4jloggeradapter.java

📁 Java开发最新的日志记录工具slf4j的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

  /**
   * Log a message at level INFO according to the specified format and argument.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the INFO level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param arg
   *                the argument
   */
  public void info(String format, Object arg) {
    if (logger.isInfoEnabled()) {
      String msgStr = MessageFormatter.format(format, arg);
      logger.log(FQCN, Level.INFO, msgStr, null);
    }
  }

  /**
   * Log a message at the INFO level according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the INFO level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param arg1
   *                the first argument
   * @param arg2
   *                the second argument
   */
  public void info(String format, Object arg1, Object arg2) {
    if (logger.isInfoEnabled()) {
      String msgStr = MessageFormatter.format(format, arg1, arg2);
      logger.log(FQCN, Level.INFO, msgStr, null);
    }
  }

  /**
   * Log a message at level INFO according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the INFO level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param argArray
   *                an array of arguments
   */
  public void info(String format, Object[] argArray) {
    if (logger.isInfoEnabled()) {
      String msgStr = MessageFormatter.arrayFormat(format, argArray);
      logger.log(FQCN, Level.INFO, msgStr, null);
    }
  }

  /**
   * Log an exception (throwable) at the INFO level with an accompanying
   * message.
   * 
   * @param msg
   *                the message accompanying the exception
   * @param t
   *                the exception (throwable) to log
   */
  public void info(String msg, Throwable t) {
    logger.log(FQCN, Level.INFO, msg, t);
  }

  /**
   * Is this logger instance enabled for the WARN level?
   * 
   * @return True if this Logger is enabled for the WARN level, false otherwise.
   */
  public boolean isWarnEnabled() {
    return logger.isEnabledFor(Level.WARN);
  }

  /**
   * Log a message object at the WARN level.
   * 
   * @param msg -
   *                the message object to be logged
   */
  public void warn(String msg) {
    logger.log(FQCN, Level.WARN, msg, null);
  }

  /**
   * Log a message at the WARN level according to the specified format and
   * argument.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the WARN level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param arg
   *                the argument
   */
  public void warn(String format, Object arg) {
    if (logger.isEnabledFor(Level.WARN)) {
      String msgStr = MessageFormatter.format(format, arg);
      logger.log(FQCN, Level.WARN, msgStr, null);
    }
  }

  /**
   * Log a message at the WARN level according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the WARN level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param arg1
   *                the first argument
   * @param arg2
   *                the second argument
   */
  public void warn(String format, Object arg1, Object arg2) {
    if (logger.isEnabledFor(Level.WARN)) {
      String msgStr = MessageFormatter.format(format, arg1, arg2);
      logger.log(FQCN, Level.WARN, msgStr, null);
    }
  }

  /**
   * Log a message at level WARN according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the WARN level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param argArray
   *                an array of arguments
   */
  public void warn(String format, Object[] argArray) {
    if (logger.isEnabledFor(Level.WARN)) {
      String msgStr = MessageFormatter.arrayFormat(format, argArray);
      logger.log(FQCN, Level.WARN, msgStr, null);
    }
  }

  /**
   * Log an exception (throwable) at the WARN level with an accompanying
   * message.
   * 
   * @param msg
   *                the message accompanying the exception
   * @param t
   *                the exception (throwable) to log
   */
  public void warn(String msg, Throwable t) {
    logger.log(FQCN, Level.WARN, msg, t);
  }

  /**
   * Is this logger instance enabled for level ERROR?
   * 
   * @return True if this Logger is enabled for level ERROR, false otherwise.
   */
  public boolean isErrorEnabled() {
    return logger.isEnabledFor(Level.ERROR);
  }

  /**
   * Log a message object at the ERROR level.
   * 
   * @param msg -
   *                the message object to be logged
   */
  public void error(String msg) {
    logger.log(FQCN, Level.ERROR, msg, null);
  }

  /**
   * Log a message at the ERROR level according to the specified format and
   * argument.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the ERROR level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param arg
   *                the argument
   */
  public void error(String format, Object arg) {
    if (logger.isEnabledFor(Level.ERROR)) {
      String msgStr = MessageFormatter.format(format, arg);
      logger.log(FQCN, Level.ERROR, msgStr, null);
    }
  }

  /**
   * Log a message at the ERROR level according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the ERROR level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param arg1
   *                the first argument
   * @param arg2
   *                the second argument
   */
  public void error(String format, Object arg1, Object arg2) {
    if (logger.isEnabledFor(Level.ERROR)) {
      String msgStr = MessageFormatter.format(format, arg1, arg2);
      logger.log(FQCN, Level.ERROR, msgStr, null);
    }
  }

  /**
   * Log a message at level ERROR according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the ERROR level.
   * </p>
   * 
   * @param format
   *                the format string
   * @param argArray
   *                an array of arguments
   */
  public void error(String format, Object[] argArray) {
    if (logger.isEnabledFor(Level.ERROR)) {
      String msgStr = MessageFormatter.arrayFormat(format, argArray);
      logger.log(FQCN, Level.ERROR, msgStr, null);
    }
  }

  /**
   * Log an exception (throwable) at the ERROR level with an accompanying
   * message.
   * 
   * @param msg
   *                the message accompanying the exception
   * @param t
   *                the exception (throwable) to log
   */
  public void error(String msg, Throwable t) {
    logger.log(FQCN, Level.ERROR, msg, t);
  }

  public void log(Marker marker, String callerFQCN, int level, String msg,
      Throwable t) {
    Level log4jLevel;
    switch (level) {
    case LocationAwareLogger.TRACE_INT:
      log4jLevel = traceCapable ? Level.TRACE : Level.DEBUG;
      break;
    case LocationAwareLogger.DEBUG_INT:
      log4jLevel = Level.DEBUG;
      break;
    case LocationAwareLogger.INFO_INT:
      log4jLevel = Level.INFO;
      break;
    case LocationAwareLogger.WARN_INT:
      log4jLevel = Level.WARN;
      break;
    case LocationAwareLogger.ERROR_INT:
      log4jLevel = Level.ERROR;
      break;
    default:
      throw new IllegalStateException("Level number " + level
          + " is not recognized.");
    }
    logger.log(callerFQCN, log4jLevel, msg, t);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -