Source code

    001/*
    002 * Copyright 2001-2004 The Apache Software Foundation.
    003 *
    004 * Licensed under the Apache License, Version 2.0 (the "License");
    005 * you may not use this file except in compliance with the License.
    006 * You may obtain a copy of the License at
    007 *
    008 *      http://www.apache.org/licenses/LICENSE-2.0
    009 *
    010 * Unless required by applicable law or agreed to in writing, software
    011 * distributed under the License is distributed on an "AS IS" BASIS,
    012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    013 * See the License for the specific language governing permissions and
    014 * limitations under the License.
    015 */
    016
    017package org.apache.log4j;
    018
    019import org.apache.log4j.spi.LoggerFactory;
    020import org.slf4j.spi.LocationAwareLogger;
    021
    022/**
    023 * <p>
    024 * This class is a minimal implementation of the original
    025 * <code>org.apache.log4j.Logger</code> class (as found in log4j 1.2)
    026 * delegating all calls to a {@link org.slf4j.Logger} instance.
    027 * </p>
    028 *
    029 * @author Ceki G&uuml;lc&uuml;
    030 * */
    031@SuppressWarnings("rawtypes")
    032public class Logger extends Category {
    033
    034    private static final String LOGGER_FQCN = Logger.class.getName();
    035
    036    protected Logger(String name) {
    037        super(name);
    038    }
    039
    040    public static Logger getLogger(String name) {
    041        return Log4jLoggerFactory.getLogger(name);
    042    }
    043
    044    public static Logger getLogger(String name, LoggerFactory loggerFactory) {
    045        return Log4jLoggerFactory.getLogger(name, loggerFactory);
    046    }
    047
    048    public static Logger getLogger(Class clazz) {
    049        return getLogger(clazz.getName());
    050    }
    051
    052    /**
    053     * Does the obvious.
    054     *
    055     * @return
    056     */
    057    public static Logger getRootLogger() {
    058        return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    059    }
    060
    061    /**
    062     * Delegates to {@link org.slf4j.Logger#isTraceEnabled}
    063     * method of SLF4J.
    064     */
    065    public boolean isTraceEnabled() {
    066        return slf4jLogger.isTraceEnabled();
    067    }
    068
    069    /**
    070     * Delegates to {@link org.slf4j.Logger#trace(String)} method in SLF4J.
    071     */
    072    public void trace(Object message) {
    073        differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
    074    }
    075
    076    /**
    077     * Delegates to {@link org.slf4j.Logger#trace(String,Throwable)}
    078     * method in SLF4J.
    079     */
    080    public void trace(Object message, Throwable t) {
    081        differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
    082    }
    083
    084}