Java 如何禁用 Spring 日志记录 DEBUG 消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21739578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable Spring logging DEBUG messages?
提问by rapt
I'm working on a simple desktop app (not webapp).
我正在开发一个简单的桌面应用程序(不是 webapp)。
Here is my log4j.properties
:
这是我的log4j.properties
:
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L $$$$ %m%n
log4j.logger.org.springframework=ERROR,stdout
As you can see, in order to eliminate Spring logging messages from the console, I tried this solution:
如您所见,为了消除控制台中的 Spring 日志消息,我尝试了以下解决方案:
Disabling Spring log, to have readable logs
When I call log4j logger from my code, the logging messages are according to the pattern specified above (which is good).
当我从我的代码中调用 log4j logger 时,日志消息是根据上面指定的模式(这很好)。
However, the bad part is - I still get to the console DEBUG level messages from spring... they look like here: Unable to disable logging messages
然而,不好的部分是 - 我仍然从 spring 到控制台调试级别的消息......它们看起来像这里: 无法禁用日志消息
And they have a different pattern. As if they ignore my settings.
他们有不同的模式。好像他们忽略了我的设置。
I also tried to apply the suggestions I've found here:
我还尝试应用我在这里找到的建议:
https://spring.io/blog/2009/12/04/logging-dependencies-in-spring
https://spring.io/blog/2009/12/04/logging-dependencies-in-spring
In my pom file:
在我的 pom 文件中:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
And no SLF4J. This option was mentioned in the above link as a valid option, if I am not wrong.
并且没有 SLF4J。如果我没记错的话,上面的链接中提到这个选项是一个有效的选项。
What might I be missing here?
我在这里可能会遗漏什么?
OUTPUT with -Dlog4j.debug=true
输出 -Dlog4j.debug=true
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@172aa3f.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@172aa3f class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@172aa3f.
log4j: Using URL [file:/C:/eclipse-workspace/workflow/target/classes/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL file:/C:/eclipse-workspace/workflow/target/classes/log4j.properties
log4j: Parsing for [root] with value=[INFO, stdout].
log4j: Level token is [INFO].
log4j: Category root set to INFO
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %t %c{2}:%L $$$$ %m%n].
log4j: End of parsing for "stdout".
log4j: Parsed "stdout" options.
log4j: Parsing for [org.springframework] with value=[ERROR,stdout].
log4j: Level token is [ERROR].
log4j: Category org.springframework set to ERROR
log4j: Parsing appender named "stdout".
log4j: Appender "stdout" was already parsed.
log4j: Handling log4j.additivity.org.springframework=[null]
log4j: Finished configuring.
23:12:42.763 [main] DEBUG o.s.core.env.StandardEnvironment - Initializing new StandardEnvironment
23:12:42.768 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
23:12:42.769 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
23:12:42.769 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
23:12:42.772 [main] INFO o.s.c.s.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7badec: startup date [Thu Feb 13 23:12:42 EST 2014]; root of context hierarchy
23:12:42.809 [main] DEBUG o.s.core.env.StandardEnvironment - Initializing new StandardEnvironment
23:12:42.810 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
23:12:42.810 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
23:12:42.810 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
23:12:42.819 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring-module.xml]
23:12:42.832 [main] DEBUG o.s.b.f.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
23:12:42.852 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
23:12:42.857 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loaded schema mappings: {http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd, http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, http://cxf.apache.org/schemas/configuration/http-conf.xsd=schemas/configuration/http-conf.xsd, http://cxf.apache.org/configuration/parameterized-types=schemas/configuration/parameterized-types.xsd, http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd=schemas/xmldsig-core-schema.xsd, http://www.springframework.org/schema/security/spring-security-3.0.3.xsd=org/springframework/security/config/spring-security-3.0.3.xsd, http://www.springframework.org/schema/aop/spring-aop-3.2.xsd=org/springframework/aop/config/spring-aop-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://www.springframework.org/schema/security/spring-security-2.0.1.xsd=org/springframework/security/config/spring-security-2.0.1.xsd, http://www.w3.org/2006/07/ws-policy.xsd=schemas/ws-policy-200607.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd=org/springframework/web/servlet/config/spring-mvc-3.2.xsd, http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd=org/springframework/oxm/config/spring-oxm-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-3.2.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/cache/spring-cache-3.2.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd=org/springframework/jdbc/config/spring-jdbc-3.1.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://schemas.xmlsoap.org/ws/2004/08/addressing=schemas/wsdl/addressing.xsd, http://www.springframework.org/schema/jee/spring-jee-3.2.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.springframework.org/schema/security/spring-security-2.0.xsd=org/springframework/security/config/spring-security-2.0.xsd, http://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd=schemas/oasis-200401-wss-wssecurity-secext-1.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop-3.1.xsd, http://schemas.xmlsoap.org/wsdl/=schemas/wsdl/wsdl.xsd, http://www.springframework.org/schema/mvc/spring-mvc.xsd=org/springframework/web/servlet/config/spring-mvc-3.2.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd=org/springframework/web/servlet/config/spring-mvc-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-3.1.xsd=org/springframework/scripting/config/spring-lang-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-3.2.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://www.springframework.org/schema/cache/spring-cache-3.1.xsd=org/springframework/cache/config/spring-cache-3.1.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd, http://schemas.xmlsoap.org/wsdl/http/=schemas/wsdl/http.xsd, http://www.springframework.org/schema/jee/spring-jee-3.1.xsd=org/springframework/ejb/config/spring-jee-3.1.xsd, http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd=schemas/oasis-200401-wss-wssecurity-utility-1.0.xsd, http://cxf.apache.org/schemas/configuration/parameterized-types.xsd=schemas/configuration/parameterized-types.xsd, http://www.springframework.org/schema/task/spring-task-3.2.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd=org/springframework/web/servlet/config/spring-mvc-3.0.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/security/spring-security-2.0.4.xsd=org/springframework/security/config/spring-security-2.0.4.xsd, http://www.springframework.org/schema/lang/spring-lang-3.0.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd, http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd=schemas/wsdl/wsdl.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://cxf.apache.org/schemas/ws/addressing.xsd=schemas/ws-addr-conf.xsd, http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/jee/spring-jee-3.0.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/task/spring-task-3.1.xsd=org/springframework/scheduling/config/spring-task-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://cxf.apache.org/schemas/wsdl/http-conf.xsd=schemas/wsdl/http-conf.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.w3.org/2001/xml.xsd=schemas/xml.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/oxm/spring-oxm.xsd=org/springframework/oxm/config/spring-oxm-3.2.xsd, http://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.w3.org/2007/02/ws-policy.xsd=schemas/ws-policy-200702.xsd, http://www.springframework.org/schema/task/spring-task.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd, http://cxf.apache.org/schemas/policy.xsd=schemas/policy.xsd, http://schemas.xmlsoap.org/ws/2004/09/policy/ws-policy.xsd=schemas/ws-policy-200409.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd=org/springframework/oxm/config/spring-oxm-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/security/spring-security-3.1.xsd=org/springframework/security/config/spring-security-3.1.xsd, http://cxf.apache.org/schemas/configuration/cxf-beans.xsd=schemas/configuration/cxf-beans.xsd, http://www.springframework.org/schema/task/spring-task-3.0.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://cxf.apache.org/schemas/core.xsd=schemas/core.xsd, http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://cxf.apache.org/schemas/configuration/security.xsd=schemas/configuration/security.xsd, http://www.springframework.org/schema/cache/spring-cache.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://cxf.apache.org/schemas/configuration/soap.xsd=schemas/configuration/soap.xsd, http://www.springframework.org/schema/security/spring-security-2.0.2.xsd=org/springframework/security/config/spring-security-2.0.2.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://cxf.apache.org/schemas/jaxws.xsd=schemas/jaxws.xsd, http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd=org/springframework/oxm/config/spring-oxm-3.1.xsd, http://cxf.apache.org/schemas/simple.xsd=schemas/simple.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-3.1.xsd, http://www.springframework.org/schema/security/spring-security-3.0.xsd=org/springframework/security/config/spring-security-3.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.2.xsd}
23:12:42.858 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.2.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.2.xsd
23:12:42.890 [main] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions
23:12:42.898 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [database/spring-datasource.xml]
23:12:42.899 [main] DEBUG o.s.b.f.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
23:12:42.901 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [http://www.springframework.org/schema/beans/spring-beans-2.5.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-2.5.xsd
23:12:42.911 [main] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions
.......................
Output with -Dorg.apache.commons.logging.diagnostics.dest=STDOUT
输出 -Dorg.apache.commons.logging.diagnostics.dest=STDOUT
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [ENV] Extension directories (java.ext.dir): null
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [ENV] Application classpath (java.class.path): C:\eclipse-workspace\workflow\target\classes;C:\eclipse-workspace\idm-authentication-service\target\classes;C:\Users\jsmith\.m2\repository\com\ln\idm\product\idm-product-service.0-SNAPSHOT\idm-product-service-1.0-SNAPSHOT.jar;C:\Users\jsmith\.m2\repository\com\ln\idm\service\idm-service.0-SNAPSHOT\idm-service-1.0-SNAPSHOT.jar;C:\Users\jsmith\.m2\repository\com\ln\idm\domain\idm-internal-api.0-SNAPSHOT\idm-internal-api-1.0-SNAPSHOT.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-databinding-xmlbeans.7.6\cxf-rt-databinding-xmlbeans-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-api.7.6\cxf-api-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\codehaus\woodstox\woodstox-core-asl.2.0\woodstox-core-asl-4.2.0.jar;C:\Users\jsmith\.m2\repository\wsdl4j\wsdl4j.6.3\wsdl4j-1.6.3.jar;C:\Users\jsmith\.m2\repository\org\apache\xmlbeans\xmlbeans.6.0\xmlbeans-2.6.0.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-core.7.6\cxf-rt-core-2.7.6.jar;C:\Users\jsmith\.m2\repository\com\sun\xml\bind\jaxb-impl.2.6\jaxb-impl-2.2.6.jar;C:\Users\jsmith\.m2\repository\org\apache\ws\xmlschema\xmlschema-core.0.3\xmlschema-core-2.0.3.jar;C:\Users\jsmith\.m2\repository\org\apache\geronimo\specs\geronimo-javamail_1.4_spec.7.1\geronimo-javamail_1.4_spec-1.7.1.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-frontend-simple.7.6\cxf-rt-frontend-simple-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-bindings-soap.7.6\cxf-rt-bindings-soap-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-databinding-jaxb.7.6\cxf-rt-databinding-jaxb-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-frontend-jaxws.7.6\cxf-rt-frontend-jaxws-2.7.6.jar;C:\Users\jsmith\.m2\repository\xml-resolver\xml-resolver.2\xml-resolver-1.2.jar;C:\Users\jsmith\.m2\repository\asm\asm.3.1\asm-3.3.1.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-bindings-xml.7.6\cxf-rt-bindings-xml-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-ws-addr.7.6\cxf-rt-ws-addr-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-ws-policy.7.6\cxf-rt-ws-policy-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\apache\neethi\neethi.0.2\neethi-3.0.2.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-transports-http.7.6\cxf-rt-transports-http-2.7.6.jar;C:\Users\jsmith\.m2\repository\org\codehaus\woodstox\woodstox-core-lgpl.2.0\woodstox-core-lgpl-4.2.0.jar;C:\Users\jsmith\.m2\repository\javax\xml\stream\stax-api.0-2\stax-api-1.0-2.jar;C:\Users\jsmith\.m2\repository\org\codehaus\woodstox\stax2-api.1.1\stax2-api-3.1.1.jar;C:\Users\jsmith\.m2\repository\org\apache\cxf\cxf-rt-ws-security.7.6\cxf-rt-ws-security-2.7.6.jar;C:\Users\jsmith\.m2\repository\net\sf\ehcache\ehcache-core.5.1\ehcache-core-2.5.1.jar;C:\Users\jsmith\.m2\repository\org\apache\ws\security\wss4j.5.8\wss4j-1.5.8.jar;C:\Users\jsmith\.m2\repository\org\apache\santuario\xmlsec.4.3\xmlsec-1.4.3.jar;C:\Users\jsmith\.m2\repository\xalan\xalan.7.1\xalan-2.7.1.jar;C:\Users\jsmith\.m2\repository\xalan\serializer.7.1\serializer-2.7.1.jar;C:\Users\jsmith\.m2\repository\dom4j\dom4j.6.1\dom4j-1.6.1.jar;C:\Users\jsmith\.m2\repository\xml-apis\xml-apis.0.b2\xml-apis-1.0.b2.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-web.2.4.RELEASE\spring-web-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\aopalliance\aopalliance.0\aopalliance-1.0.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-beans.2.4.RELEASE\spring-beans-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-tx.2.4.RELEASE\spring-tx-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-orm.2.4.RELEASE\spring-orm-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-oxm.2.4.RELEASE\spring-oxm-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-test.2.4.RELEASE\spring-test-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-mock.0.8\spring-mock-2.0.8.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-support.0.8\spring-support-2.0.8.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-webmvc.2.4.RELEASE\spring-webmvc-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-aspects.2.4.RELEASE\spring-aspects-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\aspectj\aspectjweaver.7.2\aspectjweaver-1.7.2.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-context-support.2.4.RELEASE\spring-context-support-3.2.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\apache\xbean\xbean-spring.8\xbean-spring-2.8.jar;C:\Users\jsmith\.m2\repository\org\springframework\security\spring-security-core.1.4.RELEASE\spring-security-core-3.1.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\security\spring-security-web.1.4.RELEASE\spring-security-web-3.1.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\security\spring-security-config.1.4.RELEASE\spring-security-config-3.1.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\security\spring-security-taglibs.1.4.RELEASE\spring-security-taglibs-3.1.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\security\spring-security-acl.1.4.RELEASE\spring-security-acl-3.1.4.RELEASE.jar;C:\Users\jsmith\.m2\repository\com\jhlabs\imaging\BLS\imaging-BLS.jar;C:\Users\jsmith\.m2\repository\commons-configuration\commons-configuration.6\commons-configuration-1.6.jar;C:\Users\jsmith\.m2\repository\commons-collections\commons-collections.2.1\commons-collections-3.2.1.jar;C:\Users\jsmith\.m2\repository\commons-digester\commons-digester.8\commons-digester-1.8.jar;C:\Users\jsmith\.m2\repository\commons-beanutils\commons-beanutils.7.0\commons-beanutils-1.7.0.jar;C:\Users\jsmith\.m2\repository\commons-beanutils\commons-beanutils-core.8.0\commons-beanutils-core-1.8.0.jar;C:\Users\jsmith\.m2\repository\commons-logging\commons-logging.1.1\commons-logging-1.1.1.jar;C:\Users\jsmith\.m2\repository\commons-lang\commons-lang.3\commons-lang-2.3.jar;C:\Users\jsmith\.m2\repository\org\slf4j\slf4j-api.7.5\slf4j-api-1.7.5.jar;C:\Users\jsmith\.m2\repository\org\mockito\mockito-core.9.5\mockito-core-1.9.5.jar;C:\Users\jsmith\.m2\repository\org\hamcrest\hamcrest-core.1\hamcrest-core-1.1.jar;C:\Users\jsmith\.m2\repository\org\objenesis\objenesis.1\objenesis-2.1.jar;C:\Users\jsmith\.m2\repository\org\hamcrest\hamcrest-library.3\hamcrest-library-1.3.jar;C:\Users\jsmith\.m2\repository\jaxen\jaxen.1.4\jaxen-1.1.4.jar;C:\Users\jsmith\.m2\repository\org\springmodules\spring-modules-jakarta-commonsch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
logger.setLevel(Level.toLevel("error"));
.8\spring-modules-jakarta-commons-0.8.jar;C:\Users\jsmith\.m2\repository\commons-validator\commons-validator.1.4\commons-validator-1.1.4.jar;C:\Users\jsmith\.m2\repository\commons-chain\commons-chain.1\commons-chain-1.1.jar;C:\Users\jsmith\.m2\repository\javax\portlet\portlet-api.0\portlet-api-1.0.jar;C:\Users\jsmith\.m2\repository\myfaces\myfaces-api.1.0\myfaces-api-1.1.0.jar;C:\Users\jsmith\.m2\repository\commons-codec\commons-codec.3\commons-codec-1.3.jar;C:\Users\jsmith\.m2\repository\commons-el\commons-el.0\commons-el-1.0.jar;C:\Users\jsmith\.m2\repository\commons-fileupload\commons-fileupload.0\commons-fileupload-1.0.jar;C:\Users\jsmith\.m2\repository\oro\oro.0.8\oro-2.0.8.jar;C:\Users\jsmith\.m2\repository\javax\servlet\jstl.1.2\jstl-1.1.2.jar;C:\Users\jsmith\.m2\repository\org\slf4j\jcl-over-slf4j.7.5\jcl-over-slf4j-1.7.5.jar;C:\Users\jsmith\.m2\repository\org\slf4j\jul-to-slf4j.7.5\jul-to-slf4j-1.7.5.jar;C:\Users\jsmith\.m2\repository\ch\qos\logback\logback-classic.0.13\logback-classic-1.0.13.jar;C:\Users\jsmith\.m2\repository\ch\qos\logback\logback-core.0.13\logback-core-1.0.13.jar;C:\Users\jsmith\.m2\repository\ch\qos\logback\logback-access.0.13\logback-access-1.0.13.jar;C:\eclipse-workspace\idm-verification-service\target\classes;C:\Users\jsmith\.m2\repository\junit\junit.4\junit-4.4.jar;C:\Users\jsmith\.m2\repository\log4j\log4j.2.17\log4j-1.2.17.jar;C:\Users\jsmith\.m2\repository\ca\grimtheitroade\log-annotations.0\log-annotations-1.0.jar;C:\Users\jsmith\.m2\repository\org\aspectj\aspectjrt.6.9\aspectjrt-1.6.9.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-jdbc.2.0.RELEASE\spring-jdbc-3.2.0.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-core.2.0.RELEASE\spring-core-3.2.0.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-context.2.0.RELEASE\spring-context-3.2.0.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-aop.2.0.RELEASE\spring-aop-3.2.0.RELEASE.jar;C:\Users\jsmith\.m2\repository\org\springframework\spring-expression.2.0.RELEASE\spring-expression-3.2.0.RELEASE.jar;C:\Users\jsmith\.m2\repository\mysql\mysql-connector-java.1.9\mysql-connector-java-5.1.9.jar;C:\Users\jsmith\.m2\repository\com\google\guava\guava.0.1\guava-16.0.1.jar;C:\Users\jsmith\.m2\repository\org\apache\commons\commons-lang3.2.1\commons-lang3-3.2.1.jar
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [ENV] Class org.apache.commons.logging.LogFactory was loaded via classloader sun.misc.Launcher$AppClassLoader@26290774
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [ENV] Ancestry of classloader which loaded org.apache.commons.logging.LogFactory is sun.misc.Launcher$AppClassLoader@26290774 == 'sun.misc.Launcher$AppClassLoader@1912a56'
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [ENV] Ancestry of classloader which loaded org.apache.commons.logging.LogFactory is ClassLoader tree:sun.misc.Launcher$AppClassLoader@26290774 (SYSTEM) --> sun.misc.Launcher$ExtClassLoader@24291903 --> BOOT
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] BOOTSTRAP COMPLETED
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] LogFactory implementation requested for the first time for context classloader sun.misc.Launcher$AppClassLoader@26290774
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] sun.misc.Launcher$AppClassLoader@26290774 == 'sun.misc.Launcher$AppClassLoader@1912a56'
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] ClassLoader tree:sun.misc.Launcher$AppClassLoader@26290774 (SYSTEM) --> sun.misc.Launcher$ExtClassLoader@24291903 --> BOOT
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] No properties file of name 'commons-logging.properties' found.
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] Looking for system property [org.apache.commons.logging.LogFactory] to define the LogFactory subclass to use...
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] No system property [org.apache.commons.logging.LogFactory] defined.
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] Looking for a resource file of name [META-INF/services/org.apache.commons.logging.LogFactory] to define the LogFactory subclass to use...
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] [LOOKUP] Creating an instance of LogFactory class org.apache.commons.logging.impl.SLF4JLogFactory as specified by file 'META-INF/services/org.apache.commons.logging.LogFactory' which was present in the path of the context classloader.
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] Loaded class org.apache.commons.logging.impl.SLF4JLogFactory from classloader sun.misc.Launcher$AppClassLoader@26290774
[LogFactory from sun.misc.Launcher$AppClassLoader@26290774] Created object org.apache.commons.logging.impl.SLF4JLogFactory@14185653 to manage classloader sun.misc.Launcher$AppClassLoader@26290774
09:55:35.705 [main] DEBUG o.s.core.env.StandardEnvironment - Initializing new StandardEnvironment
09:55:35.710 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
09:55:35.711 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
09:55:35.711 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
09:55:35.714 [main] INFO o.s.c.s.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1d7999e: startup date [Fri Feb 14 09:55:35 EST 2014]; root of context hierarchy
采纳答案by Stephane Nicoll
Spring uses commons-logging
which auto-detects the logging framework to use. There are various ways to tune which logging frameworkwill be chosen so the first thing to do is to make sure commons-logging
binds to log4j.
Spring 使用commons-logging
它自动检测要使用的日志记录框架。有多种方法可以调整将选择哪个日志记录框架,因此首先要做的是确保commons-logging
绑定到 log4j。
To do that, start your application with an additional flag -Dorg.apache.commons.logging.diagnostics.dest=STDOUT
that will output the result of the discovery process.
为此,请使用一个附加标志启动您的应用程序,该标志-Dorg.apache.commons.logging.diagnostics.dest=STDOUT
将输出发现过程的结果。
commons-logging delegate to log4j
公共日志记录委托到 log4j
You now need to make sure that log4j is initialise with the expected configuration. By default, log4j searches for a log4j.xml
file at the root of the classpath and fallbacks to log4j.properties
if it does not find one. It could be possible that one of the library you are using has (wrongly) a log4j.xml
file at the root.
您现在需要确保使用预期的配置初始化 log4j。默认情况下,log4jlog4j.xml
在类路径的根目录中搜索文件,log4j.properties
如果找不到则回退。您正在使用的库之一可能log4j.xml
在根目录下(错误地)有一个文件。
To debug log4j, run your application again with an additional flag -Dlog4j.debug=true
. This will output the exact loggers and the location of the configuration file.
要调试 log4j,请使用附加标志再次运行您的应用程序-Dlog4j.debug=true
。这将输出准确的记录器和配置文件的位置。
commons-logging does not delegate to log4j
commons-logging 不委托给 log4j
If commons-logging
does not delegate to log4j, this means that another logging framework is involved. The most common scenario is that your application ships with jcl-over-slf4j.jar
, a drop-in replacementof commons-logging
that uses slf4j
behind the scene.
如果commons-logging
不委托给 log4j,则意味着涉及另一个日志记录框架。最常见的情况是,您的应用程序附带jcl-over-slf4j.jar
,一个简易替换的commons-logging
使用slf4j
幕后。
In this scenario, Spring uses commons-logging
that is configured to delegate to slf4j
. So, essentially, Spring is using slf4j
. But slf4j is a simple logging facadeand needs a bindingto an actual framework.
在这种情况下,Spring 使用commons-logging
配置为委托给slf4j
. 因此,本质上,Spring 正在使用slf4j
. 但slf4j 是一个简单的日志外观,需要绑定到实际框架。
SINCE 1.6.0 If no binding is found on the class path, then SLF4J will default to a no-operation implementation.
从 1.6.0 开始,如果在类路径上找不到绑定,则 SLF4J 将默认为无操作实现。
Once you have found the binding library (it could be logback
or log4j
for instance), check the configuration of the logging framework that slf4j
is bound to.
一旦找到绑定库(可能是logback
或log4j
例如),请检查slf4j
绑定到的日志记录框架的配置。
In this particular case, you probably have logback
in your classpath. As it is a pure implementation of slf4j
, it does not need a binding library and it logs in debug if no configuration file is provided, which matches your problem actually. To fix your issue, exclude logback from your dependencies and add slf4j-log4j12
to configure slf4j with log4j.
在这种特殊情况下,您logback
的类路径中可能有。由于它是 的纯实现slf4j
,它不需要绑定库,如果没有提供配置文件,它会登录调试,这实际上符合您的问题。要解决您的问题,请从您的依赖项中排除 logback,并添加slf4j-log4j12
以使用 log4j 配置 slf4j。
Edit: updated with various comments
编辑:更新了各种评论
回答by SachinSarawgi
You have to disable commons-logging
from the dependency in pom.xml
file of the web app.
您必须禁用Web 应用程序文件中的commons-logging
依赖项pom.xml
。
Even after removing commons-logging
from pom.xml
please check the dependency hierarchy available in Eclipse or STS IDE. This will help in knowing if somehow its getting added because of some other dependency which we may not be knowing.
即使在删除之后commons-logging
,pom.xml
请检查 Eclipse 或 STS IDE 中可用的依赖关系层次结构。这将有助于了解是否由于某些我们可能不知道的其他依赖性而以某种方式添加了它。
回答by Niraj
You can disable all debug logs by just calling the below code at start of your application. And you can enable or disable at any point of time by setting log type.
您只需在应用程序启动时调用以下代码即可禁用所有调试日志。您可以通过设置日志类型随时启用或禁用。
##代码##