Why do it?
By default, LuciadLightspeed and LuciadFusion use the java.util.logger
package to log application messages .
If your application uses a logging framework other than the default Java logging framework, you can re-configure LuciadLightspeed
and LuciadFusion to dispatch log messages to that framework.
How to do it?
At initialization, LuciadLightspeed and LuciadFusion instantiate a global ILcdLoggerFactory
that determines to which framework all logging output is sent. Most logging frameworks have a very similar API, so it’s
usually quite straightforward to write an implementation of ILcdLoggerFactory
for your preferred logging framework.
To connect to your logging framework, add a file called com.luciad.util.logging.ILcdLoggerFactory
inside a META-INF/services
directory that is accessible from the classpath. This file must contain a single line with the name of your factory class.
For example:
samples.common.logging.SLF4JLoggerFactory
And that’s all there is to it.
For your convenience, the following code is a logger factory implementation for SLF4J:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.luciad.util.logging.ILcdLogger;
import com.luciad.util.logging.ILcdLoggerFactory;
/**
* Creates {@code ILcdLogger} instances that delegate to the SLF4J logging framework.
* @see ILcdLogger
*/
public class SLF4JLoggerFactory implements ILcdLoggerFactory {
@Override
public ILcdLogger getLogger(String aLoggerName) {
return new SLF4JLogger(LoggerFactory.getLogger(aLoggerName));
}
@Override
public ILcdLogger getLogger(Class aClass) {
return new SLF4JLogger(LoggerFactory.getLogger(aClass));
}
static class SLF4JLogger implements ILcdLogger {
private Logger fLogger;
SLF4JLogger(Logger aLogger) {
fLogger = aLogger;
}
@Override
public boolean isTraceEnabled() {
return fLogger.isTraceEnabled();
}
@Override
public void trace(String aMessage) {
fLogger.trace(aMessage);
}
@Override
public void trace(String aMessage, Throwable aThrowable) {
fLogger.trace(aMessage, aThrowable);
}
@Override
public void trace(String aMessage, Object aParameter) {
fLogger.trace(aMessage);
}
@Override
public void trace(String aMessage, Object aParameter, Throwable aThrowable) {
fLogger.trace(aMessage, aThrowable);
}
//----------------------------------------------------------------------------
@Override
public boolean isDebugEnabled() {
return fLogger.isDebugEnabled();
}
@Override
public void debug(String aMessage) {
fLogger.debug(aMessage);
}
@Override
public void debug(String aMessage, Throwable aThrowable) {
fLogger.debug(aMessage, aThrowable);
}
@Override
public void debug(String aMessage, Object aParameter) {
fLogger.debug(aMessage);
}
@Override
public void debug(String aMessage, Object aParameter, Throwable aThrowable) {
fLogger.debug(aMessage, aThrowable);
}
//----------------------------------------------------------------------------
@Override
public boolean isInfoEnabled() {
return fLogger.isInfoEnabled();
}
@Override
public void info(String aMessage) {
fLogger.info(aMessage);
}
@Override
public void info(String aMessage, Throwable aThrowable) {
fLogger.info(aMessage, aThrowable);
}
@Override
public void info(String aMessage, Object aParameter) {
fLogger.info(aMessage);
}
@Override
public void info(String aMessage, Object aParameter, Throwable aThrowable) {
fLogger.info(aMessage, aThrowable);
}
//----------------------------------------------------------------------------
@Override
public boolean isWarnEnabled() {
return fLogger.isWarnEnabled();
}
@Override
public void warn(String aMessage) {
fLogger.warn(aMessage);
}
@Override
public void warn(String aMessage, Throwable aThrowable) {
fLogger.warn(aMessage, aThrowable);
}
@Override
public void warn(String aMessage, Object aParameter) {
fLogger.warn(aMessage);
}
@Override
public void warn(String aMessage, Object aParameter, Throwable aThrowable) {
fLogger.warn(aMessage, aThrowable);
}
//----------------------------------------------------------------------------
@Override
public boolean isErrorEnabled() {
return fLogger.isErrorEnabled();
}
@Override
public void error(String aMessage) {
fLogger.error(aMessage);
}
@Override
public void error(String aMessage, Throwable aThrowable) {
fLogger.error(aMessage, aThrowable);
}
@Override
public void error(String aMessage, Object aParameter) {
fLogger.error(aMessage);
}
@Override
public void error(String aMessage, Object aParameter, Throwable aThrowable) {
fLogger.error(aMessage, aThrowable);
}
}
}