001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.slf4j.impl;
018    
019    import org.apache.logging.slf4j.Log4jLoggerFactory;
020    import org.slf4j.ILoggerFactory;
021    import org.slf4j.spi.LoggerFactoryBinder;
022    
023    /**
024     * SLF4J LoggerFactoryBinder implementation using Log4j. This class is part of the required classes used to specify an
025     * SLF4J logger provider implementation.
026     */
027    public final class StaticLoggerBinder implements LoggerFactoryBinder {
028    
029        /**
030         * Declare the version of the SLF4J API this implementation is compiled
031         * against. The value of this field is usually modified with each release.
032         */
033        // to avoid constant folding by the compiler, this field must *not* be final
034        public static String REQUESTED_API_VERSION = "1.6"; // !final
035    
036        private static final String LOGGER_FACTORY_CLASS_STR = Log4jLoggerFactory.class.getName();
037    
038        /**
039         * The unique instance of this class.
040         */
041        private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
042    
043        /**
044         * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
045         * method should always be the same object
046         */
047        private final ILoggerFactory loggerFactory;
048    
049        /**
050         * Private constructor to prevent instantiation
051         */
052        private StaticLoggerBinder() {
053            loggerFactory = new Log4jLoggerFactory();
054        }
055    
056        /**
057         * Returns the singleton of this class.
058         *
059         * @return the StaticLoggerBinder singleton
060         */
061        public static StaticLoggerBinder getSingleton() {
062            return SINGLETON;
063        }
064    
065        /**
066         * Returns the factory.
067         * @return the factor.
068         */
069        @Override
070        public ILoggerFactory getLoggerFactory() {
071            return loggerFactory;
072        }
073    
074        /**
075         * Returns the class name.
076         * @return the class name;
077         */
078        @Override
079        public String getLoggerFactoryClassStr() {
080            return LOGGER_FACTORY_CLASS_STR;
081        }
082    }