View Javadoc

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