001package org.slf4j.reload4j; 002 003import org.apache.log4j.Level; 004import org.slf4j.ILoggerFactory; 005import org.slf4j.IMarkerFactory; 006import org.slf4j.helpers.BasicMarkerFactory; 007import org.slf4j.helpers.Reporter; 008import org.slf4j.helpers.Util; 009import org.slf4j.spi.MDCAdapter; 010import org.slf4j.spi.SLF4JServiceProvider; 011 012public class Reload4jServiceProvider implements SLF4JServiceProvider { 013 014 /** 015 * Declare the version of the SLF4J API this implementation is compiled against. 016 * The value of this field is modified with each major release. 017 */ 018 // to avoid constant folding by the compiler, this field must *not* be final 019 public static String REQUESTED_API_VERSION = "2.0.99"; // !final 020 021 private ILoggerFactory loggerFactory; 022 023 // LoggerFactory expects providers to initialize markerFactory as early as possible. 024 private final IMarkerFactory markerFactory; 025 026 // LoggerFactory expects providers to have a valid MDCAdapter field 027 // as early as possible, preferably at construction time. 028 private final MDCAdapter mdcAdapter; 029 030 public Reload4jServiceProvider() { 031 markerFactory = new BasicMarkerFactory(); 032 mdcAdapter = new Reload4jMDCAdapter(); 033 try { 034 @SuppressWarnings("unused") 035 Level level = Level.TRACE; 036 } catch (NoSuchFieldError nsfe) { 037 Reporter.error("This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version"); 038 } 039 } 040 041 @Override 042 public void initialize() { 043 loggerFactory = new Reload4jLoggerFactory(); 044 } 045 046 @Override 047 public ILoggerFactory getLoggerFactory() { 048 return loggerFactory; 049 } 050 051 052 @Override 053 public IMarkerFactory getMarkerFactory() { 054 return markerFactory; 055 } 056 057 058 @Override 059 public MDCAdapter getMDCAdapter() { 060 return mdcAdapter; 061 } 062 063 @Override 064 public String getRequestedApiVersion() { 065 return REQUESTED_API_VERSION; 066 } 067}