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.apache.logging.slf4j.Log4jLoggerFactory;
20 import org.slf4j.ILoggerFactory;
21 import org.slf4j.spi.LoggerFactoryBinder;
22
23 /**
24 * SLF4J LoggerFactoryBinder implementation using Log4j. This class is part of the required classes used to specify an
25 * SLF4J logger provider implementation.
26 */
27 public final class StaticLoggerBinder implements LoggerFactoryBinder {
28
29 /**
30 * Declare the version of the SLF4J API this implementation is compiled
31 * against. The value of this field is usually modified with each release.
32 */
33 // to avoid constant folding by the compiler, this field must *not* be final
34 public static String REQUESTED_API_VERSION = "1.6"; // !final
35
36 private static final String LOGGER_FACTORY_CLASS_STR = Log4jLoggerFactory.class.getName();
37
38 /**
39 * The unique instance of this class.
40 */
41 private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
42
43 /**
44 * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
45 * method should always be the same object
46 */
47 private final ILoggerFactory loggerFactory;
48
49 /**
50 * Private constructor to prevent instantiation
51 */
52 private StaticLoggerBinder() {
53 loggerFactory = new Log4jLoggerFactory();
54 }
55
56 /**
57 * Returns the singleton of this class.
58 *
59 * @return the StaticLoggerBinder singleton
60 */
61 public static StaticLoggerBinder getSingleton() {
62 return SINGLETON;
63 }
64
65 /**
66 * Returns the factory.
67 * @return the factor.
68 */
69 @Override
70 public ILoggerFactory getLoggerFactory() {
71 return loggerFactory;
72 }
73
74 /**
75 * Returns the class name.
76 * @return the class name;
77 */
78 @Override
79 public String getLoggerFactoryClassStr() {
80 return LOGGER_FACTORY_CLASS_STR;
81 }
82 }