[slf4j-dev] Feature Request
Michael Poeschl
kortheo at kwanta.net
Tue Nov 24 14:15:26 CET 2009
Hey Guys,
I thought I could just write a little implementation. Basically it is your LocLogger, with a few lines changed.
package org.slf4j.cal10n;
import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.slf4j.ext.LoggerWrapper;
import org.slf4j.spi.LocationAwareLogger;
import ch.qos.cal10n.IMessageConveyor;
import ch.qos.cal10n.MessageParameterObj;
/**
* A logger specialized in localized logging. Localization is based in the <a
* href="http://cal10n.qos.ch">CAL10N project</p>.
*
* @author Ceki Gülcü
*/
public class CodeLocLogger extends LoggerWrapper implements Logger {
private static final String FQCN = CodeLocLogger.class.getName();
/**
* Every localized message logged by a LocLogger will bear this marker. It
* allows marker-aware implementations to perform additional processing on
* localized messages.
*/
static Marker LOCALIZED = MarkerFactory.getMarker("LOCALIZED");
final IMessageConveyor imc;
public CodeLocLogger(Logger logger, IMessageConveyor imc) {
super(logger, LoggerWrapper.class.getName());
if(imc == null) {
throw new IllegalArgumentException("IMessageConveyor cannot be null");
}
this.imc = imc;
}
/**
* Log a localized message at the TRACE level.
*
* @param key
* the key used for localization
* @param args
* optional arguments
*/
public void trace(Enum<?> key, Object... args) {
if (!logger.isTraceEnabled()) {
return;
}
String translatedMsg = imc.getMessage(key, args);
MessageParameterObj mpo = new MessageParameterObj(key, args);
String msg = " [" + key.getClass().getName() + key.toString() + "] " + translatedMsg;
if (instanceofLAL) {
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
LocationAwareLogger.TRACE_INT, msg, null);
} else {
logger.trace(LOCALIZED, msg, mpo);
}
}
/**
* Log a localized message at the DEBUG level.
*
* @param key
* the key used for localization
* @param args
* optional arguments
*/
public void debug(Enum<?> key, Object... args) {
if (!logger.isDebugEnabled()) {
return;
}
String translatedMsg = imc.getMessage(key, args);
MessageParameterObj mpo = new MessageParameterObj(key, args);
String msg = " [" + key.getClass().getName() + key.toString() + "] " + translatedMsg;
if (instanceofLAL) {
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
LocationAwareLogger.DEBUG_INT, msg, null);
} else {
logger.debug(LOCALIZED, msg, mpo);
}
}
/**
* Log a localized message at the INFO level.
*
* @param key
* the key used for localization
* @param args
* optional arguments
*/
public void info(Enum<?> key, Object... args) {
if (!logger.isInfoEnabled()) {
return;
}
String translatedMsg = imc.getMessage(key, args);
MessageParameterObj mpo = new MessageParameterObj(key, args);
String msg = " [" + key.getClass().getName() + key.toString() + "] " + translatedMsg;
if (instanceofLAL) {
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
LocationAwareLogger.INFO_INT, msg, null);
} else {
logger.info(LOCALIZED, msg, mpo);
}
}
/**
* Log a localized message at the WARN level.
*
* @param key
* the key used for localization
* @param args
* optional arguments
*/
public void warn(Enum<?> key, Object... args) {
if (!logger.isWarnEnabled()) {
return;
}
String translatedMsg = imc.getMessage(key, args);
MessageParameterObj mpo = new MessageParameterObj(key, args);
String msg = " [" + key.getClass().getName() + key.toString() + "] " + translatedMsg;
if (instanceofLAL) {
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
LocationAwareLogger.WARN_INT, msg, null);
} else {
logger.warn(LOCALIZED, msg, mpo);
}
}
/**
* Log a localized message at the ERROR level.
*
* @param key
* the key used for localization
* @param args
* optional arguments
*/
public void error(Enum<?> key, Object... args) {
if (!logger.isErrorEnabled()) {
return;
}
String translatedMsg = imc.getMessage(key, args);
MessageParameterObj mpo = new MessageParameterObj(key, args);
String msg = " [" + key.getClass().getName() + key.toString() + "] " + translatedMsg;
if (instanceofLAL) {
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
LocationAwareLogger.ERROR_INT, msg, null);
} else {
logger.error(LOCALIZED, msg, mpo);
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20091124/75e4d7d8/attachment.htm>
More information about the slf4j-dev
mailing list