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.apache.logging.slf4j;
018    
019    import java.net.URI;
020    
021    import org.apache.logging.log4j.spi.LoggerContext;
022    import org.apache.logging.log4j.spi.LoggerContextFactory;
023    
024    /**
025     *
026     */
027    public class SLF4JLoggerContextFactory implements LoggerContextFactory {
028        private static LoggerContext context = new SLF4JLoggerContext();
029    
030        public SLF4JLoggerContextFactory() {
031            // LOG4J2-230, LOG4J2-204 (improve error reporting when misconfigured)
032            boolean misconfigured = false;
033            try {
034                Class.forName("org.slf4j.helpers.Log4jLoggerFactory");
035                misconfigured = true;
036            } catch (ClassNotFoundException classNotFoundIsGood) {
037                // org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!
038            }
039            if (misconfigured) {
040                throw new IllegalStateException("slf4j-impl jar is mutually exclusive with log4j-to-slf4j jar "
041                        + "(the first routes calls from SLF4J to Log4j, the second from Log4j to SLF4J)");
042            }
043        }
044    
045        @Override
046        public LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext) {
047            return context;
048        }
049    
050        @Override
051        public LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext,
052                                        URI configLocation) {
053            return context;
054        }
055    
056        @Override
057        public void removeContext(LoggerContext context) {
058        }
059    }