Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't disable quartz-scheduler logging using SLF4J

After adding quartz-scheduler to a project, Tomcat's server log is being spammed with the following message:

[INFO] [talledLocalContainer] 12:15:06.319 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG o.quartz.core.QuartzSchedulerThread - batch acquisition of 0 triggers

I'm trying to disable that log message, which repeats every 25-seconds or so. I've been through a number of other answers to this same question, such as:

  • Disable quartz logging
  • stop quartz debug logging log4j
  • Disabling Log4J Output in Java

...and none of the approaches suggested are working.

I have the following dependencies declared in pom.xml:

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>

And I've added the following log4j.properties settings to my project:

log4j.rootLogger=OFF
log4j.logger.quartz=OFF
log4j.logger.o.quartz=OFF
log4j.logger.org.quartz=OFF

...and also the following simplelogger.properties:

org.slf4j.simpleLogger.defaultLogLevel=error

In addition to attempting the programmatic solution suggested on one of the linked answers, which should disable all logging and goes roughly like:

List<Logger> loggers = Collections.<Logger>list(LogManager.getCurrentLoggers());
loggers.add(LogManager.getRootLogger());
for ( Logger logger : loggers ) {
    logger.setLevel(Level.OFF);
}

That seems to disable everything except the log message from quartz when it runs.

Is there a way to get rid of the log message from quartz, short of modifying the quartz source-code to remove it?

like image 992
aroth Avatar asked Sep 29 '22 09:09

aroth


1 Answers

The logging entry above doesn't look like Log4J. I think thats ACL or JUL. When you are using Slf4j to Log4J, you also need to redirect these frameworks to Slf4j. Add these dependencies to your project as well:

<!--Redirect Apache Commons Logging to Slf4J -->
<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>jcl-over-slf4j</artifactId>
 <version>1.7.5</version>
</dependency>
<!--Redirect Java Util Logging to Slf4J -->
<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>jul-to-slf4j</artifactId>
 <version>1.7.5</version>
</dependency>

Read this doc page about redirecting Jul to Slf4J, too. Be sure to exclude any existing commons-logging.jar files from your project, through Maven.

enter image description here

(From the Slf4J documentation page)

And if all else fails, try the following code:

//see if we can find the offending logger through slf4j's LoggerFactory
org.slf4j.Logger logger = 
    LoggerFactory.getLogger(Class.forName("org.quartz.core.QuartzSchedulerThread"));
if (logger != null && logger instanceof ch.qos.logback.classic.Logger) {
    //the slf4j Logger interface doesn't expose any configuration API's, but 
    //we can cast to a class that does; so cast it and disable the logger
    ((ch.qos.logback.classic.Logger)logger).setLevel(
        ch.qos.logback.classic.Level.OFF);
}
like image 80
Stefan Avatar answered Oct 06 '22 01:10

Stefan