Logger xref

View Javadoc

    1   /*
    2    * Copyright 2001-2004 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package org.apache.log4j;
    18
    19  import org.apache.log4j.spi.LoggerFactory;
    20  import org.slf4j.spi.LocationAwareLogger;
    21
    22  /**
    23   * <p>
    24   * This class is a minimal implementation of the original
    25   * <code>org.apache.log4j.Logger</code> class (as found in log4j 1.2)
    26   * delegating all calls to a {@link org.slf4j.Logger} instance.
    27   * </p>
    28   *
    29   * @author Ceki G&uuml;lc&uuml;
    30   * */
    31  public class Logger extends Category {
    32
    33    private static final String LOGGER_FQCN = Logger.class.getName();
    34
    35    protected Logger(String name) {
    36      super(name);
    37    }
    38
    39    public static Logger getLogger(String name) {
    40      return Log4jLoggerFactory.getLogger(name);
    41    }
    42
    43    public static Logger getLogger(String name, LoggerFactory loggerFactory) {
    44      return Log4jLoggerFactory.getLogger(name,loggerFactory);
    45    }
    46
    47    public static Logger getLogger(Class clazz) {
    48      return getLogger(clazz.getName());
    49    }
    50
    51    /**
    52     * Does the obvious.
    53     *
    54     * @return
    55     */
    56    public static Logger getRootLogger() {
    57      return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    58    }
    59
    60
    61    /**
    62     * Delegates to {@link org.slf4j.Logger#isTraceEnabled}
    63     * method of SLF4J.
    64     */
    65    public boolean isTraceEnabled() {
    66      return slf4jLogger.isTraceEnabled();
    67    }
    68
    69    /**
    70     * Delegates to {@link org.slf4j.Logger#trace(String)} method in SLF4J.
    71     */
    72    public void trace(Object message) {
    73      differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
    74    }
    75
    76    /**
    77     * Delegates to {@link org.slf4j.Logger#trace(String,Throwable)}
    78     * method in SLF4J.
    79     */
    80    public void trace(Object message, Throwable t) {
    81      differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
    82    }
    83
    84  }