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