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;
020
021import java.util.Enumeration;
022import java.util.Vector;
023
024/**
025 * <p>
026 * This class is a minimal implementation of the original
027 * <code>org.apache.log4j.LogManager</code> class (as found in log4j 1.2)
028 * delegating all calls to SLF4J.
029 * <p>
030 * This implementation does <b>NOT</b> implement the setRepositorySelector(),
031 * getLoggerRepository(), exists(), getCurrentLoggers(), shutdown() and
032 * resetConfiguration() methods which do not have SLF4J equivalents.
033 *
034 * @author Ceki G&uuml;lc&uuml;
035 */
036@SuppressWarnings("rawtypes")
037public class LogManager {
038
039    public static Logger getRootLogger() {
040        return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
041    }
042
043    public static Logger getLogger(final String name) {
044        return Log4jLoggerFactory.getLogger(name);
045    }
046
047    public static Logger getLogger(final Class clazz) {
048        return Log4jLoggerFactory.getLogger(clazz.getName());
049    }
050
051    /**
052     * Returns a logger instance created by loggerFactory. This method was requested in
053     * <a href="http://jira.qos.ch/browse/SLF4J-225">SLF4J-225</a>. Note that
054     * log4j-over-slf4j does not ship with a LoggerFactory implementation. If this
055     * method is called, the caller must provide his/her own implementation.
056     *
057     * @param name          the name of the desired logger
058     * @param loggerFactory an instance of {@link LoggerFactory}
059     * @return returns a logger instance created by loggerFactory
060     * @since 1.6.6
061     */
062    public static Logger getLogger(String name, LoggerFactory loggerFactory) {
063        return loggerFactory.makeNewLoggerInstance(name);
064    }
065
066    /**
067     * This bogus implementation returns an empty enumeration.
068     *
069     * @return an Enumeration of current loggers
070     */
071    public static Enumeration getCurrentLoggers() {
072        return new Vector().elements();
073    }
074
075    /**
076     * Implemented as NOP.
077     */
078    public static void shutdown() {
079    }
080
081    /**
082     * Implemented as NOP.
083     */
084    public static void resetConfiguration() {
085    }
086}