-
Notifications
You must be signed in to change notification settings - Fork 1.9k
How to Setup Logging
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.
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.
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>
See Learn Quartz with Logback and DB example.