View Javadoc
1   package org.slf4j.reload4j;
2   
3   import org.apache.log4j.Level;
4   import org.slf4j.ILoggerFactory;
5   import org.slf4j.IMarkerFactory;
6   import org.slf4j.helpers.BasicMarkerFactory;
7   import org.slf4j.helpers.Util;
8   import org.slf4j.spi.MDCAdapter;
9   import org.slf4j.spi.SLF4JServiceProvider;
10  
11  public class Reload4jServiceProvider implements SLF4JServiceProvider {
12  
13      /**
14       * Declare the version of the SLF4J API this implementation is compiled against. 
15       * The value of this field is modified with each major release. 
16       */
17      // to avoid constant folding by the compiler, this field must *not* be final
18      public static String REQUESTED_API_VERSION = "2.0.99"; // !final
19  
20      private ILoggerFactory loggerFactory;
21      private IMarkerFactory markerFactory;
22      private MDCAdapter mdcAdapter;
23  
24      public Reload4jServiceProvider() {
25          try {
26              @SuppressWarnings("unused")
27              Level level = Level.TRACE;
28          } catch (NoSuchFieldError nsfe) {
29              Util.report("This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version");
30          }
31      }
32  
33      @Override
34      public void initialize() {
35          loggerFactory = new Reload4jLoggerFactory();
36          markerFactory = new BasicMarkerFactory();
37          mdcAdapter = new Reload4jMDCAdapter();
38      }
39  
40      @Override
41      public ILoggerFactory getLoggerFactory() {
42          return loggerFactory;
43      }
44  
45  
46      @Override
47      public IMarkerFactory getMarkerFactory() {
48          return markerFactory;
49      }
50  
51  
52      @Override
53      public MDCAdapter getMDCAdapter() {
54          return mdcAdapter;
55      }
56  
57      @Override
58      public String getRequestedApiVersion() {
59          return REQUESTED_API_VERSION;
60      }
61  }