Best practice logging implementation for Java — Logback

pom.xml:
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.1</version>
            <scope>compile</scope>
        </dependency>
src/main/java/resources/logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>
Calling the logging facility from within Java code: 
private static final Logger LOG = LoggerFactory.getLogger(YourClass.class);
// is not shown because the log level is set to "info"
LOG.debug("DEBUG");
// is shown because the log level warn is of higher precedence than "info"
LOG.warn("WARN");
// is shown because the "info" log level has been explicitly specified
LOG.info("INFO"); 

Comments

Popular posts from this blog

Tuning ext4 for performance with emphasis on SSD usage

NetBeans 6.1: Working with Google´s Android SDK, Groovy and Grails