2014-02-25 143 views
5

我在我的類路徑下面的log4j.xml文件:重複Log4J日誌

<appender class="org.apache.log4j.ConsoleAppender" name="Console"> 
    <param name="Threshold" value="info" /> 
    <layout class="org.apache.log4j.PatternLayout"> 
     <param value="%d %-5p [%t] %C (%F:%L) - %m%n" name="ConversionPattern"/> 
    </layout> 
    <filter class="org.apache.log4j.varia.LevelRangeFilter"> 
     <param value="info" name="LevelMax"/> 
     <param value="info" name="LevelMin"/> 
    </filter> 
</appender> 

<logger name="de.scm.cci.importer"> 
    <level value="info"/> 
</logger> 

<logger name="com.mchange"> 
    <level value="info"/> 
</logger> 
<logger name="jdbc"> 
    <level value="error"/> 
</logger> 
<logger name="org.hibernate"> 
    <level value="info"/> 
</logger> 
<logger name="org.springframework"> 
    <level value="info"/> 
</logger> 

<root> 
    <level value="INFO"/> 
    <appender-ref ref="Console"/> 
</root> 

下面是輸出的前幾行:

log4j: Trying to find [log4j.xml] using context classloader [email protected] 
log4j: Using URL [file:/opt/app/cci/CCIImporter/jar/log4j.xml] for automatic log4j configuration. 
log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator 
log4j: System property is :null 
log4j: Standard DocumentBuilderFactory search succeded. 
log4j: DocumentBuilderFactory is: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 
log4j: debug attribute= "true". 
log4j: reset attribute= "false". 
log4j: Threshold ="null". 
log4j: Retreiving an instance of org.apache.log4j.Logger. 
log4j: Setting [de.scm.cci.importer] additivity to [true]. 
log4j: Level value for de.scm.cci.importer is [info]. 
log4j: de.scm.cci.importer level set to INFO 
log4j: Retreiving an instance of org.apache.log4j.Logger. 
log4j: Setting [com.mchange] additivity to [true]. 
log4j: Level value for com.mchange is [info]. 
log4j: com.mchange level set to INFO 
log4j: Retreiving an instance of org.apache.log4j.Logger. 
log4j: Setting [jdbc] additivity to [true]. 
log4j: Level value for jdbc is [error]. 
log4j: jdbc level set to ERROR 
log4j: Retreiving an instance of org.apache.log4j.Logger. 
log4j: Setting [org.hibernate] additivity to [true]. 
log4j: Level value for org.hibernate is [info]. 
log4j: org.hibernate level set to INFO 
log4j: Retreiving an instance of org.apache.log4j.Logger. 
log4j: Setting [org.springframework] additivity to [true]. 
log4j: Level value for org.springframework is [info]. 
log4j: org.springframework level set to INFO 
log4j: Level value for root is [INFO]. 
log4j: root level set to INFO 
log4j: Class name: [org.apache.log4j.ConsoleAppender] 
log4j: Setting property [threshold] to [INFO]. 
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout" 
log4j: Setting property [conversionPattern] to [%d %-5p [%t] %C (%F:%L) - %m%n]. 
log4j: Setting property [levelMax] to [INFO]. 
log4j: Setting property [levelMin] to [INFO]. 
log4j: Adding filter of type [class org.apache.log4j.varia.LevelRangeFilter] to appender named [Console]. 
log4j: Adding appender named [Console] to category [root]. 
2014-02-25 13:20:25,534 INFO [main] de.scm.cci.importer.RunTest (RunTest.java:21) - Starting loop mode 
2014-02-25 13:20:25,537 INFO [main] de.scm.cci.importer.RunTest (RunTest.java:24) - Started... 
PERSISTENCE LOADING 
2014-02-25 13:20:25,767 INFO [main] org.springframework.context.support.AbstractApplicationContext (AbstractApplicationContext.java:513) - Refreshing org[email protected]52545254: startup date [Tue Feb 25 13:20:25 CET 2014]; root of context hierarchy 
233 [main] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org[email protected]52545254: startup date [Tue Feb 25 13:20:25 CET 2014]; root of context hierarchy 
2014-02-25 13:20:25,877 INFO [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader (XmlBeanDefinitionReader.java:316) - Loading XML bean definitions from class path resource [de/scm/cci/backend/public/spring-config.xml] 

一旦彈簧開始加載,輸出的每一行都在加倍:

2014-02-25 13:20:25,767 INFO [main] org.springframework.context.support.AbstractApplicationContext (AbstractApplicationContext.java:513) - Refreshing org[email protected]52545254: startup date [Tue Feb 25 13:20:25 CET 2014]; root of context hierarchy 
233 [main] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org[email protected]52545254: startup date [Tue Feb 25 13:20:25 CET 2014]; root of context hierarchy 

我完全無能爲力,其中第二行來自。

編輯: 奇怪:我收到警告消息,儘管我設置所有可能的threasholds和東西僅INFO ...?

回答

3

因爲你只有一個的appender聲明的,重複的日誌的格式一樣,它似乎很清楚,你有多個日誌框架會在同一時間:在

  • log4j的你春天裏的

自己的代碼

  • 共享記錄,你需要做的是:

    • 從您的類路徑中刪除commons-logging依賴項。如果您使用的是maven,則必須在每個彈簧模塊中排除來自的常見測井廣告瓶。
    • 添加JCL-過SLF4J到classpath

    Maven的例子(如何刪除共享記錄):注意:您需要在每一個春天的依賴

    <dependency> 
        <groupId>org.springframework</groupId> 
        <artifactId>spring-web</artifactId> 
        <version>${spring.version}</version> 
        <exclusions> 
        <exclusion> 
         <artifactId>commons-logging</artifactId> 
         <groupId>commons-logging</groupId> 
        </exclusion> 
        </exclusions> 
    </dependency> 
    

    這種排斥語法Maven的例子(如何添加SLF4J,你可能已經這樣做):如果你不使用Maven

    <dependency> 
        <groupId>org.slf4j</groupId> 
        <artifactId>slf4j-api</artifactId> 
        <version>1.7.7</version> 
    </dependency> 
    
    <dependency> 
        <groupId>org.slf4j</groupId> 
        <artifactId>jcl-over-slf4j</artifactId> 
        <version>1.7.7</version> 
    </dependency> 
    

    ,讓我知道,我會盡力幫助您的具體環境。

  • +0

    那好吧,這似乎是訣竅!我目前還沒有使用maven,並從類路徑中刪除了commons-logging jar。 jcl-over-sl4j目前不在,可能會導致問題?我現在無法全面測試,可能是本週末。 – DocJones

    +0

    我不確定在使用基本的log4j時是否存在問題,但是如果您嘗試通過slf4j使用log4j,則需要使用jcl-over-slf4j軟件包。 – durron597

    1

    Spring Framework不直接使用log4j - 它使用commons-logging。

    它的行爲取決於應用程序類路徑中的其他日誌記錄實現。

    什麼日誌記錄相關的罐子在你的班級路徑?

    +0

    好的,我如何從這裏出發?我明白,我有不同的記錄機制混合起來。我假設我還必須配置commons-logging以及看看它在哪裏? – DocJones