org.apache.commons.logging.impl.LogKitLogger Maven / Gradle / Ivy
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.log.Logger;
import org.apache.log.Hierarchy;
import org.apache.commons.logging.Log;
/**
* Implementation of org.apache.commons.logging.Log
* that wraps the avalon-logkit
* logging system. Configuration of LogKit
is left to the user.
*
*
* LogKit
accepts only String
messages.
* Therefore, this implementation converts object messages into strings
* by called their toString()
method before logging them.
*
* @author Scott Sanders
* @author Robert Burrell Donkin
* @version $Id: LogKitLogger.java,v 1.9 2004/06/01 19:56:46 rdonkin Exp $
*/
public class LogKitLogger implements Log, Serializable {
// ------------------------------------------------------------- Attributes
/** Logging goes to this LogKit
logger */
protected transient Logger logger = null;
/** Name of this logger */
protected String name = null;
// ------------------------------------------------------------ Constructor
/**
* Construct LogKitLogger
which wraps the LogKit
* logger with given name.
*
* @param name log name
*/
public LogKitLogger(String name) {
this.name = name;
this.logger = getLogger();
}
// --------------------------------------------------------- Public Methods
/**
* Return the underlying Logger we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Hierarchy.getDefaultHierarchy().getLoggerFor(name);
}
return (logger);
}
// ----------------------------------------------------- Log Implementation
/**
* Log message to LogKit
logger with DEBUG
priority.
*/
public void trace(Object message) {
debug(message);
}
/**
* Log error to LogKit
logger with DEBUG
priority.
*/
public void trace(Object message, Throwable t) {
debug(message, t);
}
/**
* Log message to LogKit
logger with DEBUG
priority.
*/
public void debug(Object message) {
if (message != null) {
getLogger().debug(String.valueOf(message));
}
}
/**
* Log error to LogKit
logger with DEBUG
priority.
*/
public void debug(Object message, Throwable t) {
if (message != null) {
getLogger().debug(String.valueOf(message), t);
}
}
/**
* Log message to LogKit
logger with INFO
priority.
*/
public void info(Object message) {
if (message != null) {
getLogger().info(String.valueOf(message));
}
}
/**
* Log error to LogKit
logger with INFO
priority.
*/
public void info(Object message, Throwable t) {
if (message != null) {
getLogger().info(String.valueOf(message), t);
}
}
/**
* Log message to LogKit
logger with WARN
priority.
*/
public void warn(Object message) {
if (message != null) {
getLogger().warn(String.valueOf(message));
}
}
/**
* Log error to LogKit
logger with WARN
priority.
*/
public void warn(Object message, Throwable t) {
if (message != null) {
getLogger().warn(String.valueOf(message), t);
}
}
/**
* Log message to LogKit
logger with ERROR
priority.
*/
public void error(Object message) {
if (message != null) {
getLogger().error(String.valueOf(message));
}
}
/**
* Log error to LogKit
logger with ERROR
priority.
*/
public void error(Object message, Throwable t) {
if (message != null) {
getLogger().error(String.valueOf(message), t);
}
}
/**
* Log message to LogKit
logger with FATAL_ERROR
priority.
*/
public void fatal(Object message) {
if (message != null) {
getLogger().fatalError(String.valueOf(message));
}
}
/**
* Log error to LogKit
logger with FATAL_ERROR
priority.
*/
public void fatal(Object message, Throwable t) {
if (message != null) {
getLogger().fatalError(String.valueOf(message), t);
}
}
/**
* Check whether the LogKit
logger will log messages of priority DEBUG
.
*/
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Check whether the LogKit
logger will log messages of priority ERROR
.
*/
public boolean isErrorEnabled() {
return getLogger().isErrorEnabled();
}
/**
* Check whether the LogKit
logger will log messages of priority FATAL_ERROR
.
*/
public boolean isFatalEnabled() {
return getLogger().isFatalErrorEnabled();
}
/**
* Check whether the LogKit
logger will log messages of priority INFO
.
*/
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
/**
* Check whether the LogKit
logger will log messages of priority DEBUG
.
*/
public boolean isTraceEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Check whether the LogKit
logger will log messages of priority WARN
.
*/
public boolean isWarnEnabled() {
return getLogger().isWarnEnabled();
}
}