View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.slf4j.impl;
8   
9   import org.mule.module.logging.MuleLoggerFactory;
10  
11  import org.apache.log4j.Level;
12  import org.slf4j.ILoggerFactory;
13  import org.slf4j.LoggerFactory;
14  import org.slf4j.helpers.Util;
15  import org.slf4j.spi.LoggerFactoryBinder;
16  
17  /**
18   * The binding of {@link LoggerFactory} class with an actual instance of
19   * {@link ILoggerFactory} is performed using information returned by this class.
20   * Bound to Mule logger instead.
21   */
22  public class StaticLoggerBinder implements LoggerFactoryBinder {
23  
24    /**
25     * The unique instance of this class.
26     * 
27     */
28    private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
29  
30    /**
31     * Return the singleton of this class.
32     * 
33     * @return the StaticLoggerBinder singleton
34     */
35    public static final StaticLoggerBinder getSingleton() {
36      return SINGLETON;
37    }
38  
39    /**
40     * Declare the version of the SLF4J API this implementation is compiled
41     * against. The value of this field is usually modified with each release.
42     */
43    // to avoid constant folding by the compiler, this field must *not* be final
44    public static String REQUESTED_API_VERSION = "1.6"; // !final
45  
46    private static final String loggerFactoryClassStr = MuleLoggerFactory.class
47        .getName();
48  
49    /**
50     * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
51     * method should always be the same object
52     */
53    private final ILoggerFactory loggerFactory;
54  
55    private StaticLoggerBinder() {
56      loggerFactory = new MuleLoggerFactory();
57      try {
58        Level level = Level.TRACE;
59      } catch (NoSuchFieldError nsfe) {
60        Util
61            .report("This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version");
62      }
63    }
64  
65    public ILoggerFactory getLoggerFactory() {
66      return loggerFactory;
67    }
68  
69    public String getLoggerFactoryClassStr() {
70      return loggerFactoryClassStr;
71    }
72  }