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.Util;
008import org.slf4j.spi.MDCAdapter;
009import org.slf4j.spi.SLF4JServiceProvider;
010
011public class Reload4jServiceProvider implements SLF4JServiceProvider {
012
013    /**
014     * Declare the version of the SLF4J API this implementation is compiled against. 
015     * The value of this field is modified with each major release. 
016     */
017    // to avoid constant folding by the compiler, this field must *not* be final
018    public static String REQUESTED_API_VERSION = "2.0.99"; // !final
019
020    private ILoggerFactory loggerFactory;
021    private IMarkerFactory markerFactory;
022    private MDCAdapter mdcAdapter;
023
024    public Reload4jServiceProvider() {
025        try {
026            @SuppressWarnings("unused")
027            Level level = Level.TRACE;
028        } catch (NoSuchFieldError nsfe) {
029            Util.report("This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version");
030        }
031    }
032
033    @Override
034    public void initialize() {
035        loggerFactory = new Reload4jLoggerFactory();
036        markerFactory = new BasicMarkerFactory();
037        mdcAdapter = new Reload4jMDCAdapter();
038    }
039
040    @Override
041    public ILoggerFactory getLoggerFactory() {
042        return loggerFactory;
043    }
044
045
046    @Override
047    public IMarkerFactory getMarkerFactory() {
048        return markerFactory;
049    }
050
051
052    @Override
053    public MDCAdapter getMDCAdapter() {
054        return mdcAdapter;
055    }
056
057    @Override
058    public String getRequestedApiVersion() {
059        return REQUESTED_API_VERSION;
060    }
061}