1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.slf4j;
18
19 import java.net.URI;
20
21 import org.apache.logging.log4j.spi.LoggerContext;
22 import org.apache.logging.log4j.spi.LoggerContextFactory;
23 import org.apache.logging.log4j.status.StatusLogger;
24 import org.apache.logging.log4j.util.LoaderUtil;
25
26 public class SLF4JLoggerContextFactory implements LoggerContextFactory {
27 private static final StatusLogger LOGGER = StatusLogger.getLogger();
28 private static final LoggerContext context = new SLF4JLoggerContext();
29
30 public SLF4JLoggerContextFactory() {
31
32 boolean misconfigured = false;
33 try {
34 LoaderUtil.loadClass("org.slf4j.helpers.Log4jLoggerFactory");
35 misconfigured = true;
36 } catch (final ClassNotFoundException classNotFoundIsGood) {
37 LOGGER.debug("org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!");
38 }
39 if (misconfigured) {
40 throw new IllegalStateException("slf4j-impl jar is mutually exclusive with log4j-to-slf4j jar "
41 + "(the first routes calls from SLF4J to Log4j, the second from Log4j to SLF4J)");
42 }
43 }
44
45 @Override
46 public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
47 final boolean currentContext) {
48 return context;
49 }
50
51 @Override
52 public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
53 final boolean currentContext, final URI configLocation, final String name) {
54 return context;
55 }
56
57 @Override
58 public void removeContext(final LoggerContext ignored) {
59 }
60
61 @Override
62 public boolean isClassLoaderDependent() {
63
64 return false;
65 }
66 }