stop quartz debug logging log4j

2019-04-12 01:09发布

问题:

i'm stuck trying to turn off the annoying DEBUG logging of quartz. i'm using log4j as logging framework and i've already tried to add this line to the lg4j proprieties file

"log4j.logger.org.quartz=ERROR"

i'm still getting tons of these debugging logging messages

13:35:44.680 [MyScheduler_QuartzSchedulerThread] DEBUG o.quartz.core.QuartzSchedulerThread - batch acquisition of 0 triggers

how can i turn this function off ?

EDIT. i've moved my configuration to xml file...but still getting the same annoying problem

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration>
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
        </layout>
    </appender>

    <logger name="org.quartz" >
        <level value="ERROR" />
        <appender-ref ref="console" />
    </logger>

    <logger name="org.hibernate">
        <level value="ERROR" />
        <appender-ref ref="console" />
    </logger>

    <logger name="com.mchange.v2.c3p0" additivity="false">
        <level value="ERROR" />
        <appender-ref ref="console" />
    </logger>

    <root>
        <priority value="ERROR" />
        <appender-ref ref="console" />
    </root>
</log4j:configuration>

EDIT2...here's my pom.xml file (interesting part)

<!-- slf4j-log4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
        </dependency>
<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.9</version>
        </dependency>
<!-- QUARTZ -->
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.1.7</version>
        </dependency>

EDIT3 jar in classpath

activation-1.1.jar
ant-1.8.2.jar
ant-launcher-1.8.2.jar
antlr-2.7.7.jar
asm-1.5.3.jar
asm-attrs-1.5.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
bcmail-jdk14-1.38.jar
bcmail-jdk14-138.jar
bcprov-jdk14-1.38.jar
bcprov-jdk14-138.jar
bctsp-jdk14-1.38.jar
c3p0-0.9.1.1.jar
castor-1.2.jar
cglib-2.1_3.jar
commons-beanutils-1.8.3.jar
commons-codec-1.5.jar
commons-collections-3.2.1.jar
commons-digester-2.1.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
filename.txt
freemarker-2.3.18.jar
groovy-all-2.1.3.jar
hibernate-3.2.7.ga.jar
hibernate-annotations-3.3.0.ga.jar
hibernate-c3p0-4.1.10.Final.jar
hibernate-commons-annotations-3.3.0.ga.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.10.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
itext-2.1.7.jar
jackson-annotations-2.0.5.jar
jackson-core-2.0.5.jar
jackson-databind-2.0.5.jar
jasperreports-5.1.0.jar
javassist-3.11.0.GA.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
jcommon-1.0.15.jar
jdbc-mysql.jar
jdtcore-3.1.0.jar
jfreechart-1.0.12.jar
jta-1.1.jar
log4j-1.2.9.jar
logback-classic-1.0.10.jar
logback-core-1.0.11.jar
mail-1.4.jar
mysql-connector-java-5.1.6.jar
ognl-3.0.4.jar
ooxml-schemas-1.1.jar
openxml4j-1.0-beta.jar
poi-3.9.jar
poi-contrib-3.7-beta3.jar
poi-examples-3.9.jar
poi-excelant-3.9.jar
poi-ooxml-3.9.jar
poi-ooxml-schemas-3.9.jar
poi-scratchpad-3.9.jar
quartz-2.1.7.jar
servlet-api-2.5.jar
slf4j-api-1.7.2.jar
slf4j-log4j12-1.6.1.jar
stax-api-1.0.1.jar
struts2-core-2.3.1.2.jar
struts2-json-plugin-2.3.1.2.jar
xml-apis-1.0.b2.jar
xmlbeans-2.3.0.jar
xwork-core-2.3.1.2.jar

回答1:

Quartz uses SLF4J as the logging API. Therefore you should be able to configure the level in your Log4j config file.

Please verify the following:

1. You have no version conflict.

The easiest way to assure this is to let maven choose the versions.

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

slf4j-log4j12 will include both, Log4J and SLF4J.

2. Make sure your config file known to Log4J.

It should be in the classpath (e.g. src/main/resources for maven projects) and it should be called log4j.xml.



回答2:

If you are using Logback(intended as a successor to the popular log4j project), you can turn off the debug log by adding a logger to the <configuration /> as below:

<logger name="org.quartz.core.QuartzSchedulerThread" level="WARN" />


回答3:

quartz-2.2.2 uses slf4j which supports logback. so adding logback.xml to the classpath and setting appropriate log level will resolve the issue. In case you are using another version of quartz and if it supports log4j. please ignore this.

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>

    <logger name="org.quartz" level="ERROR"/>

    <root level="ALL">
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} | %-5level | %X{username} | %thread | %logger{1} | %m%n%rEx</pattern>
            </encoder>
        </appender>
    </root>
</configuration>


回答4:

Quartz is not using log4j, but it's using java.util.logging.Logger.



回答5:

I reset my log4j.xml to

 <root> 
    <priority value ="info" /> 
    <appender-ref ref="console" /> 
  </root>