/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.logging.impl; import java.io.Serializable; import org.apache.commons.logging.Log; import org.apache.log4j.Logger; import org.apache.log4j.Priority; import org.apache.log4j.Level; /** * Implementation of {@link Log} that maps directly to a * Logger for log4J version 1.2. *
* Initial configuration of the corresponding Logger instances should be done * in the usual manner, as outlined in the Log4J documentation. *
* The reason this logger is distinct from the 1.3 logger is that in version 1.2 * of Log4J: *
org.apache.log4j.Priority.TRACE.
* When using a log4j version that does not support the TRACE
* level, the message will be logged at the DEBUG level.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
getLogger().log(FQCN, traceLevel, message, null );
}
/**
* Logs a message with org.apache.log4j.Priority.TRACE.
* When using a log4j version that does not support the TRACE
* level, the message will be logged at the DEBUG level.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable t) {
getLogger().log(FQCN, traceLevel, message, t );
}
/**
* Logs a message with org.apache.log4j.Priority.DEBUG.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
getLogger().log(FQCN, Priority.DEBUG, message, null );
}
/**
* Logs a message with org.apache.log4j.Priority.DEBUG.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable t) {
getLogger().log(FQCN, Priority.DEBUG, message, t );
}
/**
* Logs a message with org.apache.log4j.Priority.INFO.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
getLogger().log(FQCN, Priority.INFO, message, null );
}
/**
* Logs a message with org.apache.log4j.Priority.INFO.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable t) {
getLogger().log(FQCN, Priority.INFO, message, t );
}
/**
* Logs a message with org.apache.log4j.Priority.WARN.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
getLogger().log(FQCN, Priority.WARN, message, null );
}
/**
* Logs a message with org.apache.log4j.Priority.WARN.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable t) {
getLogger().log(FQCN, Priority.WARN, message, t );
}
/**
* Logs a message with org.apache.log4j.Priority.ERROR.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
getLogger().log(FQCN, Priority.ERROR, message, null );
}
/**
* Logs a message with org.apache.log4j.Priority.ERROR.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable t) {
getLogger().log(FQCN, Priority.ERROR, message, t );
}
/**
* Logs a message with org.apache.log4j.Priority.FATAL.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
getLogger().log(FQCN, Priority.FATAL, message, null );
}
/**
* Logs a message with org.apache.log4j.Priority.FATAL.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable t) {
getLogger().log(FQCN, Priority.FATAL, message, t );
}
/**
* Return the native Logger instance we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(name);
}
return (this.logger);
}
/**
* Check whether the Log4j Logger used is enabled for DEBUG priority.
*/
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Check whether the Log4j Logger used is enabled for ERROR priority.
*/
public boolean isErrorEnabled() {
return getLogger().isEnabledFor(Priority.ERROR);
}
/**
* Check whether the Log4j Logger used is enabled for FATAL priority.
*/
public boolean isFatalEnabled() {
return getLogger().isEnabledFor(Priority.FATAL);
}
/**
* Check whether the Log4j Logger used is enabled for INFO priority.
*/
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
/**
* Check whether the Log4j Logger used is enabled for TRACE priority.
* When using a log4j version that does not support the TRACE level, this call
* will report whether DEBUG is enabled or not.
*/
public boolean isTraceEnabled() {
return getLogger().isEnabledFor(traceLevel);
}
/**
* Check whether the Log4j Logger used is enabled for WARN priority.
*/
public boolean isWarnEnabled() {
return getLogger().isEnabledFor(Priority.WARN);
}
}