java – 重复log4j日志记录

前端之家收集整理的这篇文章主要介绍了java – 重复log4j日志记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我的classpath中有以下log4j.xml文件

以下是前几行输出

  1. log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@7220722.
  2. log4j: Using URL [file:/opt/app/cci/CCIImporter/jar/log4j.xml] for automatic log4j configuration.
  3. log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator
  4. log4j: System property is :null
  5. log4j: Standard DocumentBuilderFactory search succeded.
  6. log4j: DocumentBuilderFactory is: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
  7. log4j: debug attribute= "true".
  8. log4j: reset attribute= "false".
  9. log4j: Threshold ="null".
  10. log4j: Retreiving an instance of org.apache.log4j.Logger.
  11. log4j: Setting [de.scm.cci.importer] additivity to [true].
  12. log4j: Level value for de.scm.cci.importer is [info].
  13. log4j: de.scm.cci.importer level set to INFO
  14. log4j: Retreiving an instance of org.apache.log4j.Logger.
  15. log4j: Setting [com.mchange] additivity to [true].
  16. log4j: Level value for com.mchange is [info].
  17. log4j: com.mchange level set to INFO
  18. log4j: Retreiving an instance of org.apache.log4j.Logger.
  19. log4j: Setting [jdbc] additivity to [true].
  20. log4j: Level value for jdbc is [error].
  21. log4j: jdbc level set to ERROR
  22. log4j: Retreiving an instance of org.apache.log4j.Logger.
  23. log4j: Setting [org.hibernate] additivity to [true].
  24. log4j: Level value for org.hibernate is [info].
  25. log4j: org.hibernate level set to INFO
  26. log4j: Retreiving an instance of org.apache.log4j.Logger.
  27. log4j: Setting [org.springframework] additivity to [true].
  28. log4j: Level value for org.springframework is [info].
  29. log4j: org.springframework level set to INFO
  30. log4j: Level value for root is [INFO].
  31. log4j: root level set to INFO
  32. log4j: Class name: [org.apache.log4j.ConsoleAppender]
  33. log4j: Setting property [threshold] to [INFO].
  34. log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
  35. log4j: Setting property [conversionPattern] to [%d %-5p [%t] %C (%F:%L) - %m%n].
  36. log4j: Setting property [levelMax] to [INFO].
  37. log4j: Setting property [levelMin] to [INFO].
  38. log4j: Adding filter of type [class org.apache.log4j.varia.LevelRangeFilter] to appender named [Console].
  39. log4j: Adding appender named [Console] to category [root].
  40. 2014-02-25 13:20:25,534 INFO [main] de.scm.cci.importer.RunTest (RunTest.java:21) - Starting loop mode
  41. 2014-02-25 13:20:25,537 INFO [main] de.scm.cci.importer.RunTest (RunTest.java:24) - Started...
  42. PERSISTENCE LOADING
  43. 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
  44. 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
  45. 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]

一旦spring开始加载,输出的每一行都加倍:

  1. 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
  2. 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

我完全无能为力,第二条线来自哪里.

编辑:
很奇怪:我收到WARN消息,尽管事实上我只将所有可能的threasholds和东西设置为INFO ……?

最佳答案
因为您只声明了一个appender,并且重复日志的格式不同,所以很明显您有多个日志框架同时进行:

> log4j在您自己的代码
>在Spring内部进行公共记录

你需要做的是:

>从类路径中删除commons-logging依赖项.如果您使用的是maven,则必须从每个Spring模块中排除commons-logging jar.
>将jcl-over-slf4j添加到类路径中

Maven示例(如何删除commons-logging):注意:在每个Spring依赖项中都需要这种排除语法

Maven示例(如何添加slf4j,您可能已经这样做了):

如果您不使用Maven,请告诉我,我会尽力帮助您了解您的特定环境.

猜你在找的Spring相关文章