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 
21 import java.util.Enumeration;
22 import java.util.Vector;
23 
24 /**
25  * <p/>
26  * This class is a minimal implementation of the original
27  * <code>org.apache.log4j.LogManager</code> class (as found in log4j 1.2)
28  * delegating all calls to SLF4J.
29  * <p/>
30  * <p/>
31  * This implementation does <b>NOT</b> implement the setRepositorySelector(),
32  * getLoggerRepository(), exists(), getCurrentLoggers(), shutdown() and
33  * resetConfiguration() methods which do not have SLF4J equivalents.
34  *
35  * @author Ceki G&uuml;lc&uuml;
36  */
37 @SuppressWarnings("rawtypes")
38 public class LogManager {
39 
getRootLogger()40     public static Logger getRootLogger() {
41         return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
42     }
43 
getLogger(final String name)44     public static Logger getLogger(final String name) {
45         return Log4jLoggerFactory.getLogger(name);
46     }
47 
getLogger(final Class clazz)48     public static Logger getLogger(final Class clazz) {
49         return Log4jLoggerFactory.getLogger(clazz.getName());
50     }
51 
52     /**
53      * Returns a logger instance created by loggerFactory. This method was requested in
54      * <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=234">bug #234</a>. Note that
55      * log4j-over-slf4j does not ship with a LoggerFactory implementation. If this
56      * method is called, the caller must provide his/her own implementation.
57      *
58      * @param name          the name of the desired logger
59      * @param loggerFactory an instance of {@link LoggerFactory}
60      * @return returns a logger instance created by loggerFactory
61      * @since 1.6.6
62      */
getLogger(String name, LoggerFactory loggerFactory)63     public static Logger getLogger(String name, LoggerFactory loggerFactory) {
64         return loggerFactory.makeNewLoggerInstance(name);
65     }
66 
67     /**
68      * This bogus implementation returns an empty enumeration.
69      *
70      * @return
71      */
getCurrentLoggers()72     public static Enumeration getCurrentLoggers() {
73         return new Vector().elements();
74     }
75 
76     /**
77      * Implemented as NOP.
78      */
shutdown()79     public static void shutdown() {
80     }
81 
82     /**
83      * Implemented as NOP.
84      */
resetConfiguration()85     public static void resetConfiguration() {
86     }
87 }
88