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

📄 loggerwrapper.java

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

import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;

/**
 * A helper class wrapping an {@link org.slf4j.Logger}
 * instance preserving location information if the wrapped
 * instance supports it.
 * 
 * @author Ralph Goers
 * @author Ceki Gülcü
 */
public class LoggerWrapper implements Logger {

  // To ensure consistency between two instances sharing the same name (homonyms)
  // a LoggerWrapper should not contain any state beyond 
  // the Logger instance it wraps.
  // Note that 'instanceofLAL' directly depends on Logger.
  // fqcn depend on the caller, but its value would not be different
  // between successive invocations of a factory class
  
  final Logger logger;
  final String fqcn;
  // is this logger instance a LocationAwareLogger
  final boolean instanceofLAL;
  
  public LoggerWrapper(Logger logger, String fqcn) {
    this.logger = logger;
    this.fqcn = fqcn;
    if (logger instanceof LocationAwareLogger) {
      instanceofLAL = true;
    } else {
      instanceofLAL = false;
    }
  }
  
  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public boolean isTraceEnabled() {
    return logger.isTraceEnabled();
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public boolean isTraceEnabled(Marker marker) {
    return logger.isTraceEnabled(marker);
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(String msg) {
    if (!logger.isTraceEnabled())
      return;

    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.TRACE_INT, msg, null);
    } else {
      logger.trace(msg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(String format, Object arg) {
    if (!logger.isTraceEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.TRACE_INT, formattedMessage, null);
    } else {
      logger.trace(format, arg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(String format, Object arg1, Object arg2) {
    if (!logger.isTraceEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.TRACE_INT, formattedMessage, null);
    } else {
      logger.trace(format, arg1, arg2);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(String format, Object[] argArray) {
    if (!logger.isTraceEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.TRACE_INT, formattedMessage, null);
    } else {
      logger.trace(format, argArray);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(String msg, Throwable t) {
    if (!logger.isTraceEnabled())
      return;

    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.TRACE_INT, msg, t);
    } else {
      logger.trace(msg, t);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(Marker marker, String msg) {
    if (!logger.isTraceEnabled())
      return;
    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.TRACE_INT, msg, null);
    } else {
      logger.trace(marker, msg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(Marker marker, String format, Object arg) {
    if (!logger.isTraceEnabled())
      return;
    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg);
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.TRACE_INT, formattedMessage, null);
    } else {
      logger.trace(marker, format, arg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(Marker marker, String format, Object arg1, Object arg2) {
    if (!logger.isTraceEnabled())
      return;
    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.TRACE_INT, formattedMessage, null);
    } else {
      logger.trace(marker, format, arg1, arg2);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(Marker marker, String format, Object[] argArray) {
    if (!logger.isTraceEnabled())
      return;
    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.TRACE_INT, formattedMessage, null);
    } else {
      logger.trace(marker, format, argArray);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void trace(Marker marker, String msg, Throwable t) {
    if (!logger.isTraceEnabled())
      return;
    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.TRACE_INT, msg, t);
    } else {
      logger.trace(marker, msg, t);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public boolean isDebugEnabled() {
    return logger.isDebugEnabled();
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public boolean isDebugEnabled(Marker marker) {
    return logger.isDebugEnabled(marker);
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(String msg) {
    if (!logger.isDebugEnabled())
      return;

    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.DEBUG_INT, msg, null);
    } else {
      logger.debug(msg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(String format, Object arg) {
    if (!logger.isDebugEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
    } else {
      logger.debug(format, arg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(String format, Object arg1, Object arg2) {
    if (!logger.isDebugEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
    } else {
      logger.debug(format, arg1, arg2);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(String format, Object[] argArray) {
    if (!logger.isDebugEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
    } else {
      logger.debug(format, argArray);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(String msg, Throwable t) {
    if (!logger.isDebugEnabled())
      return;

    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.DEBUG_INT, msg, t);
    } else {
      logger.debug(msg, t);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(Marker marker, String msg) {
    if (!logger.isDebugEnabled())
      return;
    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.DEBUG_INT, msg, null);
    } else {
      logger.debug(marker, msg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(Marker marker, String format, Object arg) {
    if (!logger.isDebugEnabled())
      return;
    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg);
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
    } else {
      logger.debug(marker, format, arg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(Marker marker, String format, Object arg1, Object arg2) {
    if (!logger.isDebugEnabled())
      return;
    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
    } else {
      logger.debug(marker, format, arg1, arg2);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(Marker marker, String format, Object[] argArray) {
    if (!logger.isDebugEnabled())
      return;
    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
    } else {
      logger.debug(marker, format, argArray);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void debug(Marker marker, String msg, Throwable t) {
    if (!logger.isDebugEnabled())
      return;
    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(marker, fqcn,
          LocationAwareLogger.DEBUG_INT, msg, t);
    } else {
      logger.debug(marker, msg, t);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public boolean isInfoEnabled() {
    return logger.isInfoEnabled();
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public boolean isInfoEnabled(Marker marker) {
    return logger.isInfoEnabled(marker);
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void info(String msg) {
    if (!logger.isInfoEnabled())
      return;

    if (instanceofLAL) {
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.INFO_INT, msg, null);
    } else {
      logger.info(msg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void info(String format, Object arg) {
    if (!logger.isInfoEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.INFO_INT, formattedMessage, null);
    } else {
      logger.info(format, arg);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void info(String format, Object arg1, Object arg2) {
    if (!logger.isInfoEnabled())
      return;

    if (instanceofLAL) {
      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
      ((LocationAwareLogger) logger).log(null, fqcn,
          LocationAwareLogger.INFO_INT, formattedMessage, null);
    } else {
      logger.info(format, arg1, arg2);
    }
  }

  /**
   * Delegate to the appropriate method of the underlying logger.
   */
  public void info(String format, Object[] argArray) {
    if (!logger.isInfoEnabled())

⌨️ 快捷键说明

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