at.spardat.xma.boot.logger.XmaBrtLogger Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
/*
* @(#) $Id: XmaBrtLogger.java 2084 2007-11-27 14:53:31Z s3460 $
*/
package at.spardat.xma.boot.logger;
import org.apache.commons.logging.Log;
/**
* Implementation of the org.apache.commons.logging.Log
* interface that wraps the XMA Bootruntime Logger Implementation
*
* This class is used to pipe log entries produced by the cookie implementation of
* apache httpClient into the logfile of XMA Bootruntime.
*
* @author Bernhard Gruber
*/
public class XmaBrtLogger implements Log {
/** allow/disallow tracing **/
private static boolean traceEnabled=false;
/**
* The underlying Logger implementation we are using.
*/
protected transient Logger logger = null;
/**
* The name of the logger we are wrapping.
*/
protected String name = null;
/**
* Construct a named instance of this Logger.
* @param name Name of the logger to be constructed
*/
public XmaBrtLogger(String name) {
this.name = name;
logger = getLogger();
}
/**
* Logs a message with java.util.logging.Level.FINE
.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
logger.log(LogLevel.FINE, String.valueOf(message));
}
/**
* Logs a message with java.util.logging.Level.FINE
.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable exception) {
logger.log(LogLevel.FINE, String.valueOf(message), exception);
}
/**
* Logs a message with java.util.logging.Level.SEVERE
.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
logger.log(LogLevel.SEVERE, String.valueOf(message));
}
/**
* Logs a message with java.util.logging.Level.SEVERE
.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable exception) {
logger.log(LogLevel.SEVERE, String.valueOf(message), exception);
}
/**
* Logs a message with java.util.logging.Level.SEVERE
.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
logger.log(LogLevel.SEVERE, String.valueOf(message));
}
/**
* Logs a message with java.util.logging.Level.SEVERE
.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable exception) {
logger.log(LogLevel.SEVERE, String.valueOf(message), exception);
}
/**
* Return the native Logger instance we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(name);
}
return logger;
}
/**
* Logs a message with java.util.logging.Level.INFO
.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
logger.log(LogLevel.INFO, String.valueOf(message));
}
/**
* Logs a message with java.util.logging.Level.INFO
.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable exception) {
logger.log(LogLevel.INFO, String.valueOf(message), exception);
}
/**
* Is debug logging currently enabled?
*/
public boolean isDebugEnabled() {
return logger.getLevel().intValue() <= LogLevel.FINE.intValue();
}
/**
* Is error logging currently enabled?
*/
public boolean isErrorEnabled() {
return logger.getLevel().intValue() <= LogLevel.SEVERE.intValue();
}
/**
* Is fatal logging currently enabled?
*/
public boolean isFatalEnabled() {
return logger.getLevel().intValue() <= LogLevel.SEVERE.intValue();
}
/**
* Is info logging currently enabled?
*/
public boolean isInfoEnabled() {
return logger.getLevel().intValue() <= LogLevel.INFO.intValue();
}
/**
* Is trace logging currently enabled?
*/
public boolean isTraceEnabled() {
return traceEnabled && (logger.getLevel().intValue() <= LogLevel.ALL.intValue());
}
/**
* Is warn logging currently enabled?
*/
public boolean isWarnEnabled() {
return logger.getLevel().intValue() <= LogLevel.WARNING.intValue();
}
/**
* Logs a message with java.util.logging.Level.ALL
.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
if(traceEnabled) {
logger.log(LogLevel.ALL, String.valueOf(message));
}
}
/**
* Logs a message with java.util.logging.Level.ALL
.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable exception) {
if(traceEnabled) {
logger.log(LogLevel.ALL, String.valueOf(message), exception);
}
}
/**
* Logs a message with java.util.logging.Level.WARNING
.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
logger.log(LogLevel.WARNING, String.valueOf(message));
}
/**
* Logs a message with java.util.logging.Level.WARNING
.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable exception) {
logger.log(LogLevel.WARNING, String.valueOf(message), exception);
}
}