Tuesday, June 11, 2013

Simple slf4j configuration with Maven

Just add the following dependencies to your project pom.xml. The slf4j logging will be up and running with default implementation of logback configuration. The default configuration shows logs of DEBUG and above level for all packages.

Each dependencies are explained below -


  1. slf4j-api - slf4j api which you will use in your code to log messages.
  2. commons-logging - note the version this is too exclude all the commons-logging dependencies coming from other dependencies of your project. This version is available at http://version99.qos.ch/commons-logging/commons-logging/99-empty/
  3. logback-* - logback implementation which will be used to configure/control the logging. You can choose to use log4j or other implementation also.
  4. jcl-over-slf4j - enables migration from commons logging to slf4j without any code changes
  5. log4j-over-slf4jenables migration from log4j logging to slf4j without any code changes
  6. jul-over-slf4jenables migration from java util logging to slf4j without any code changes
  7. osgi-over-slf4jenables migration from osgi logging to slf4j without any code changes


        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>99-empty</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.0.11</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.11</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-access</artifactId>
            <version>1.0.11</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>1.7.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>osgi-over-slf4j</artifactId>
            <version>1.7.5</version>
            <scope>runtime</scope>
        </dependency>

No comments:

Post a Comment