Skip to content

Logging

rmuthupandian edited this page Feb 11, 2015 · 1 revision

Jetstream framework uses sl4fj api for logging, and by default it does not bind to any slf4j impl. A specific slf4j impl can be chosen by you during the process of building and deploying your application.

Typically, we recommend to use logback as the slf4j impl. In order to use logback you need to add the following dependency in your project pom.xml file

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.1.2</version>
    </dependency>

In addition it requires a configuration as shown below supplied in a file named logback.xml under the src/main/resouces.

    <configuration scan="false" scanPeriod="10 seconds">
        <!-- Rolling file -->
        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>

            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>logs/jetstream-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>10 MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
                <maxHistory>10</maxHistory>
            </rollingPolicy>

            <prudent>false</prudent>
        </appender>


        <!-- Console output -->
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>INFO</level>
            </filter>
        </appender>

        <root level="INFO">
            <appender-ref ref="FILE" />
            <appender-ref ref="STDOUT" />
        </root>
    </configuration>

The default logger level is INFO, and it will log to console and also to rotated log files under the /logs folder.

If you use other logging frameworks you can use the bridge provided by slf4j. For example if you are using log4j then adding the dependency sepcification shown below will redirect log4j/commons-logging/jdk-logging to slf4j. See detail from http://www.slf4j.org/legacy.html

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <version>1.7.10</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.10</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>1.7.10</version>
    </dependency>

By default, the Jetstream applications created by using the Jetstream archetype will use above logging configuration. The jetstreamdemo project in the jetstream repo also uses above logging configuration.

Clone this wiki locally