[FrontPage] [TitleIndex] [WordIndex

deegree 3 Logging System

deegree 3 uses Simple Logging Facade for Java (SLF4J). SLF4J is a wrapper library for other logging frameworks. deegree 3 uses log4j as the default implementation.

1. Usage

To create a log instance use the following code snippet:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class XXX {
    private static final Logger LOG = LoggerFactory.getLogger( XXX.class );

To log something:

// some simple log message
LOG.error( "some error happened here" );

SLF4J can format the log message:

LOG.debug( "got {} with {}", foo.getName(), foo.getArg() );
// or
LOG.debug( "got {} with {} during {}", new Object[] {foo.getName(), foo.getArg(), this.state} );

The variable substitution and the toString calls will only be performed when the log level is enabled. Other expensive calculations should be wrapped with a guard.

if ( LOG.isDebugEnabled() ) {
    int foo = calculateCurrentFooFactor( );
    LOG.debug( "current foo factor: {}", foo );

1.1. deegree 3 Logging Extension

The deegree 2 logging system has some methods to log strings or binary data into files (e.g. to log a whole XML file, etc.). This functionality is now in org.deegree.commons.utils.LogUtils.

// LOG is the local log object
LogUtils.writeTempFile( LOG, "capabilities", "xml", contents );

1.2. BootLogger

deegree 2 used a BootLogger for logging within static blocks, this is not necessary anymore.

2. Configuration

2.1. Logging Implementation

The logging system is configured explicitly with the selection of an appropriate logging jar. deegree 3 comes with slf4j-log4j12.jar, a binding for the log4j framework. You can change this jar though. Please read http://www.slf4j.org/manual.html for more information, if you need to use another framework for the actual logging.

2.2. log4j Configuration

deegree 3 comes with a log4j.properties that configures the log output. It is located in the src directory of deegree and should be placed in the .jar or classes directory. This is usually handled by the build process. To overwrite the configuration for debugging, etc. you can add your own modified version of the file to the classpath of your application. In tomcat you would put the file in WEB-INF/classes.

By default deegree logs INFO, ERROR, WARN and FATAL messages (i.e. no DEBUG and TRACE). The output goes to the console and into a deegree.log in your home directory.


2018-04-20 12:05