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
27
28
29 public class SLF4JLoggerContextFactory implements LoggerContextFactory {
30 private static final StatusLogger LOGGER = StatusLogger.getLogger();
31 private static LoggerContext context = new SLF4JLoggerContext();
32
33 public SLF4JLoggerContextFactory() {
34
35 boolean misconfigured = false;
36 try {
37 LoaderUtil.loadClass("org.slf4j.helpers.Log4jLoggerFactory");
38 misconfigured = true;
39 } catch (final ClassNotFoundException classNotFoundIsGood) {
40 LOGGER.debug("org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!");
41 }
42 if (misconfigured) {
43 throw new IllegalStateException("slf4j-impl jar is mutually exclusive with log4j-to-slf4j jar "
44 + "(the first routes calls from SLF4J to Log4j, the second from Log4j to SLF4J)");
45 }
46 }
47
48 @Override
49 public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
50 final boolean currentContext) {
51 return context;
52 }
53
54 @Override
55 public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
56 final boolean currentContext, final URI configLocation, final String name) {
57 return context;
58 }
59
60 @Override
61 public void removeContext(final LoggerContext ignored) {
62 }
63 }