Skip to content

How to Setup Logging

Zemian Deng edited this page Apr 2, 2019 · 4 revisions

The Quartz Scheduler uses SLF4J API for logging. This means it only bind to a thin logger wrapper API, and itself does not provide logging implementation! Users/developers must choose an logger implementation to use along with Quartz+SLF4J in order to control the logging output. There are many SLF4J logger implementation choices out there that you may use. Note that each logger implementation would have their own configuration format. You would need to consult their documentation to learn to use them.

Using Quartz with slf4j-simple

The slf4j-simple is so simple, you don’t even need to configure anything. Just add the dependency into your Maven project, and you are good to go!

    <dependencies>
        <!-- Quartz -->
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- Quartz uses SLF4J, so we need an actual logger -->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-simple</artifactId>
          <version>1.7.7</version>
        </dependency>
    </dependencies>

Then it will default logging INFO level messages. If you want to see DEBUG verbose messages, then add this System Property -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG.

See quartz-quick-start example.

Using Quartz with logback

Logback is a very popular logger implementation that is production ready and packed with many features. Configuring it would require you to read their documentation to use it properly. Here we provide you a quick Maven setup and an example of the configuration file.

    <dependencies>
        <!-- Quartz -->
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- Quartz uses SLF4J, so we need an actual logger -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
    </dependencies>

Then add this src/main/resources/logback.xml file in your project

<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>

    <logger name="org.quartz" level="DEBUG"/>
</configuration>