When using log4j, as an alternative, it can be used with the "Log4jLoggerAdapter", defining the configuration in the .properties file. The code is below.
Necessary banks:
slf4j-api-1.7.5.jar slf4j-log4j12-1.7.5.jar If desired the source code (useful when debugging): slf4j-api-1.7.5-sources.jar slf4j-log4j12-1.7.5-sources.jar
Testing java class:
import org.apache.log4j.PropertyConfigurator; import org.slf4j.LoggerFactory; import org.slf4j.impl.Log4jLoggerAdapter; public class Slf4j_log4j_main { private static Log4jLoggerAdapter log = (Log4jLoggerAdapter) LoggerFactory.getLogger(Slf4j_log4j_main.class); public static void main(String[] args) { PropertyConfigurator.configure(Slf4j_log4j_main.class.getClassLoader().getResource("basic/log4j.properties")); log.debug( "a debug" ); log.info( "an info" ); log.warn("a warn"); log.error("an error");
Essentials / log4j.properties
Generated Output:
2013-06-14 11:47:00,473 [main] DEBUG basic.Slf4j_log4j_main - a debug 2013-06-14 11:47:00,474 [main] INFO basic.Slf4j_log4j_main - an info 2013-06-14 11:47:00,474 [main] WARN basic.Slf4j_log4j_main - a warn 2013-06-14 11:47:00,475 [main] ERROR basic.Slf4j_log4j_main - an error [INFO]: done
source share