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  
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  public class LogManager {
38  
39    public static Logger getRootLogger() {
40      return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
41    }
42  
43    public static Logger getLogger(final String name) {
44      return Log4jLoggerFactory.getLogger(name);
45    }
46  
47    public static Logger getLogger(final Class clazz) {
48      return Log4jLoggerFactory.getLogger(clazz.getName());
49    }
50  
51    /**
52     * Returns a logger instance created by loggerFactory. This method was requested in
53     * <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=234">bug #234</a>. Note that
54     * log4j-over-slf4j does not ship with a LoggerFactory implementation. If this
55     * method is called, the caller must provide his/her own implementation.
56     *
57     * @param name          the name of the desired logger
58     * @param loggerFactory an instance of {@link LoggerFactory}
59     * @return returns a logger instance created by loggerFactory
60     * @since 1.6.6
61     */
62    public static Logger getLogger(String name, LoggerFactory loggerFactory) {
63      return loggerFactory.makeNewLoggerInstance(name);
64    }
65  
66    /**
67     * This bogus implementation returns an empty enumeration.
68     *
69     * @return
70     */
71    public static Enumeration getCurrentLoggers() {
72      return new Vector().elements();
73    }
74  
75    /**
76     * Implemented as NOP.
77     */
78    public static void shutdown() {
79    }
80  
81    /**
82     * Implemented as NOP.
83     */
84    public static void resetConfiguration() {
85    }
86  }