001/* 002 * Copyright 2001-2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.apache.log4j; 018 019import org.apache.log4j.spi.LoggerFactory; 020import org.slf4j.spi.LocationAwareLogger; 021 022/** 023 * <p> 024 * This class is a minimal implementation of the original 025 * <code>org.apache.log4j.Logger</code> class (as found in log4j 1.2) 026 * delegating all calls to a {@link org.slf4j.Logger} instance. 027 * 028 * 029 * @author Ceki Gülcü 030 * */ 031@SuppressWarnings("rawtypes") 032public class Logger extends Category { 033 034 private static final String LOGGER_FQCN = Logger.class.getName(); 035 036 protected Logger(String name) { 037 super(name); 038 } 039 040 public static Logger getLogger(String name) { 041 return Log4jLoggerFactory.getLogger(name); 042 } 043 044 public static Logger getLogger(String name, LoggerFactory loggerFactory) { 045 return Log4jLoggerFactory.getLogger(name, loggerFactory); 046 } 047 048 public static Logger getLogger(Class clazz) { 049 return getLogger(clazz.getName()); 050 } 051 052 /** 053 * Does the obvious. 054 * 055 * @return the root logger 056 */ 057 public static Logger getRootLogger() { 058 return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); 059 } 060 061 /** 062 * Delegates to {@link org.slf4j.Logger#isTraceEnabled} 063 * method of SLF4J. 064 * 065 * @return whether this logger is enabled for the level TRACE 066 */ 067 public boolean isTraceEnabled() { 068 return slf4jLogger.isTraceEnabled(); 069 } 070 071 /** 072 * Delegates to {@link org.slf4j.Logger#trace(String)} method in SLF4J. 073 * 074 * @param message the message to log 075 * 076 */ 077 public void trace(Object message) { 078 differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null); 079 } 080 081 /** 082 * Delegates to {@link org.slf4j.Logger#trace(String,Throwable)} 083 * method in SLF4J. 084 * 085 * @param message the message to log 086 * @param t a Throwable to log 087 */ 088 public void trace(Object message, Throwable t) { 089 differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, t); 090 } 091 092}