View Javadoc
1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.log4j;
18  
19  import org.apache.log4j.spi.LoggerFactory;
20  import org.slf4j.spi.LocationAwareLogger;
21  
22  /**
23   * <p>
24   * This class is a minimal implementation of the original
25   * <code>org.apache.log4j.Logger</code> class (as found in log4j 1.2) 
26   * delegating all calls to a {@link org.slf4j.Logger} instance.
27   * 
28   *
29   * @author Ceki G&uuml;lc&uuml; 
30   * */
31  @SuppressWarnings("rawtypes")
32  public class Logger extends Category {
33  
34      private static final String LOGGER_FQCN = Logger.class.getName();
35  
36      protected Logger(String name) {
37          super(name);
38      }
39  
40      public static Logger getLogger(String name) {
41          return Log4jLoggerFactory.getLogger(name);
42      }
43  
44      public static Logger getLogger(String name, LoggerFactory loggerFactory) {
45          return Log4jLoggerFactory.getLogger(name, loggerFactory);
46      }
47  
48      public static Logger getLogger(Class clazz) {
49          return getLogger(clazz.getName());
50      }
51  
52      /**
53       * Does the obvious.
54       * 
55       * @return the root logger
56       */
57      public static Logger getRootLogger() {
58          return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
59      }
60  
61      /**
62       * Delegates to {@link org.slf4j.Logger#isTraceEnabled} 
63       * method of SLF4J.
64       * 
65       * @return whether this logger is enabled for the level TRACE
66       */
67      public boolean isTraceEnabled() {
68          return slf4jLogger.isTraceEnabled();
69      }
70  
71      /**
72       * Delegates to {@link org.slf4j.Logger#trace(String)} method in SLF4J.
73       *     
74       * @param message the message to log
75       *      
76       */
77      public void trace(Object message) {
78          differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
79      }
80  
81      /**
82       * Delegates to {@link org.slf4j.Logger#trace(String,Throwable)} 
83       * method in SLF4J.
84       * 
85       * @param message the message to log
86       * @param t a Throwable to log
87       */
88      public void trace(Object message, Throwable t) {
89          differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, t);
90      }
91  
92  }