View Javadoc

1   /**
2    * Copyright (c) 2004-2011 QOS.ch
3    * All rights reserved.
4    *
5    * Permission is hereby granted, free  of charge, to any person obtaining
6    * a  copy  of this  software  and  associated  documentation files  (the
7    * "Software"), to  deal in  the Software without  restriction, including
8    * without limitation  the rights to  use, copy, modify,  merge, publish,
9    * distribute,  sublicense, and/or sell  copies of  the Software,  and to
10   * permit persons to whom the Software  is furnished to do so, subject to
11   * the following conditions:
12   *
13   * The  above  copyright  notice  and  this permission  notice  shall  be
14   * included in all copies or substantial portions of the Software.
15   *
16   * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
17   * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
18   * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
19   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21   * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
22   * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23   *
24   */
25  package org.slf4j.impl;
26  
27  import org.apache.log4j.Level;
28  import org.slf4j.ILoggerFactory;
29  import org.slf4j.helpers.Util;
30  import org.slf4j.log4j12.Log4jLoggerFactory;
31  import org.slf4j.spi.LoggerFactoryBinder;
32  
33  /**
34  * As of SLF4J version 1.8.0, the static binder mechanism is deprecated. 
35  * 
36  * <p>This class exists for backward compatibility earlier versions of slf4j-api.jar, 
37  * in particular in the 1.6.x and the 1.7.x series.</p>
38  * 
39  * <p>Note that this class is likely to be removed in future releases of SLF4J.</p>
40  * 
41  * @author Ceki G&uuml;lc&uuml;
42  */
43  public class StaticLoggerBinder implements LoggerFactoryBinder {
44  
45      /**
46       * The unique instance of this class.
47       * 
48       */
49      private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
50  
51      /**
52       * Return the singleton of this class.
53       * 
54       * @return the StaticLoggerBinder singleton
55       */
56      public static final StaticLoggerBinder getSingleton() {
57          return SINGLETON;
58      }
59  
60      /**
61       *  Declare compatibility with the 1.6.x and the 1.7.x series
62       */
63      // to avoid constant folding by the compiler, this field must *not* be final
64      public static String REQUESTED_API_VERSION = "1.6.99"; // !final
65  
66      private static final String loggerFactoryClassStr = Log4jLoggerFactory.class.getName();
67  
68      /**
69       * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
70       * method should always be the same object
71       */
72      private final ILoggerFactory loggerFactory;
73  
74      private StaticLoggerBinder() {
75          loggerFactory = new Log4jLoggerFactory();
76          try {
77              @SuppressWarnings("unused")
78              Level level = Level.TRACE;
79          } catch (NoSuchFieldError nsfe) {
80              Util.report("This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version");
81          }
82      }
83  
84      public ILoggerFactory getLoggerFactory() {
85          return loggerFactory;
86      }
87  
88      public String getLoggerFactoryClassStr() {
89          return loggerFactoryClassStr;
90      }
91  }