首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重复log4j测井

重复log4j测井
EN

Stack Overflow用户
提问于 2014-02-25 12:23:12
回答 1查看 6.9K关注 0票数 5

我的类路径中有以下log4j.xml文件:

代码语言:javascript
复制
<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>

下面是输出的前几行:

代码语言:javascript
复制
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@7220722.
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.springframework.context.support.ClassPathXmlApplicationContext@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.springframework.context.support.ClassPathXmlApplicationContext@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]

一旦弹簧开始加载,输出的每一行就翻了一番:

代码语言:javascript
复制
2014-02-25 13:20:25,767 INFO  [main] org.springframework.context.support.AbstractApplicationContext (AbstractApplicationContext.java:513) - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@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.springframework.context.support.ClassPathXmlApplicationContext@52545254: startup date [Tue Feb 25 13:20:25 CET 2014]; root of context hierarchy

我完全不知道第二行从何而来。

编辑:够奇怪了:我收到警告消息,尽管我设置了所有可能的理由和材料,只有信息…?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-05 12:41:40

由于您只声明了一个附录,并且重复日志的格式是而不是,所以很明显,您有多个日志记录框架同时运行:

  • log4j在您自己的代码中
  • 共享- Spring中的日志

你需要做的是:

  • 从类路径中移除公用日志依赖项。如果您使用的是maven,则必须从每个Spring模块中排除公用日志jar。
  • 将jcl-over slf4j添加到类路径中。

Maven示例(如何删除共享日志):注意:您需要在每个Spring依赖项中使用这种排除语法

代码语言:javascript
复制
<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,您可能已经在这样做了):

代码语言:javascript
复制
<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>

如果您不使用Maven,请告诉我,我将尽力帮助您的特定环境。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22014123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档