View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.slf4j.impl;
18  
19  import org.slf4j.ILoggerFactory;
20  import org.slf4j.helpers.Log4jLoggerFactory;
21  import org.slf4j.spi.LoggerFactoryBinder;
22  
23  /**
24   *
25   */
26  public final class StaticLoggerBinder implements LoggerFactoryBinder {
27  
28      /**
29       * Declare the version of the SLF4J API this implementation is compiled
30       * against. The value of this field is usually modified with each release.
31       */
32      // to avoid constant folding by the compiler, this field must *not* be final
33      public static String REQUESTED_API_VERSION = "1.6"; // !final
34  
35      private static final String LOGGER_FACTORY_CLASS_STR = Log4jLoggerFactory.class.getName();
36  
37      /**
38       * The unique instance of this class.
39       */
40      private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
41  
42      /**
43       * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
44       * method should always be the same object
45       */
46      private final ILoggerFactory loggerFactory;
47  
48      /**
49       * Private constructor to prevent instantiation
50       */
51      private StaticLoggerBinder() {
52          loggerFactory = new Log4jLoggerFactory();
53      }
54  
55      /**
56       * Returns the singleton of this class.
57       *
58       * @return the StaticLoggerBinder singleton
59       */
60      public static StaticLoggerBinder getSingleton() {
61          return SINGLETON;
62      }
63  
64      /**
65       * Returns the factory.
66       * @return the factor.
67       */
68      @Override
69      public ILoggerFactory getLoggerFactory() {
70          return loggerFactory;
71      }
72  
73      /**
74       * Returns the class name.
75       * @return the class name;
76       */
77      @Override
78      public String getLoggerFactoryClassStr() {
79          return LOGGER_FACTORY_CLASS_STR;
80      }
81  }