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