我知道有很多类似的问题,但我尝试了几乎所有提供的答案。他们都没有帮助我。最突出的是this one。
我用-Dorg.apache.commons.logging.diagnostics.dest=STDOUT -Dlog4j.debug=true
启动了我的应用,看看发生了什么。这就是我得到的:
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [ENV] Extension directories (java.ext.dir): null
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [ENV] Application classpath (java.class.path): D:\springsource\vfabric-tc-server-developer-2.9.5.SR1\tomcat-7.0.50.C.RELEASE\bin\bootstrap.jar;D:\springsource\vfabric-tc-server-developer-2.9.5.SR1\tomcat-7.0.50.C.RELEASE\bin\tomcat-juli.jar;C:\Program Files (x86)\Java\jdk1.7.0_60\lib\tools.jar
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [ENV] Class org.apache.commons.logging.LogFactory was loaded via classloader org.apache.catalina.loader.WebappClassLoader@14797796
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [ENV] Ancestry of classloader which loaded org.apache.commons.logging.LogFactory is org.apache.catalina.loader.WebappClassLoader@14797796 == 'WebappClassLoader
context: /myApp
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1e6cecc
'
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [ENV] Ancestry of classloader which loaded org.apache.commons.logging.LogFactory is ClassLoader tree:org.apache.catalina.loader.WebappClassLoader@14797796 --> org.apache.catalina.loader.StandardClassLoader@31903436 --> sun.misc.Launcher$AppClassLoader@5898991 (SYSTEM) --> sun.misc.Launcher$ExtClassLoader@24558058 --> BOOT
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] BOOTSTRAP COMPLETED
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [LOOKUP] LogFactory implementation requested for the first time for context classloader org.apache.catalina.loader.WebappClassLoader@14797796
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [LOOKUP] org.apache.catalina.loader.WebappClassLoader@14797796 == 'WebappClassLoader
context: /myApp
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1e6cecc
'
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [LOOKUP] ClassLoader tree:org.apache.catalina.loader.WebappClassLoader@14797796 --> org.apache.catalina.loader.StandardClassLoader@31903436 --> sun.misc.Launcher$AppClassLoader@5898991 (SYSTEM) --> sun.misc.Launcher$ExtClassLoader@24558058 --> BOOT
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [LOOKUP] No properties file of name 'commons-logging.properties' found.
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [LOOKUP] Looking for system property [org.apache.commons.logging.LogFactory] to define the LogFactory subclass to use...
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [LOOKUP] No system property [org.apache.commons.logging.LogFactory] defined.
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] [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 org.apache.catalina.loader.WebappClassLoader@14797796] [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 org.apache.catalina.loader.WebappClassLoader@14797796] Loaded class org.apache.commons.logging.impl.SLF4JLogFactory from classloader org.apache.catalina.loader.WebappClassLoader@14797796
[LogFactory from org.apache.catalina.loader.WebappClassLoader@14797796] Created object org.apache.commons.logging.impl.SLF4JLogFactory@20683303 to manage classloader org.apache.catalina.loader.WebappClassLoader@14797796
ruj 23, 2014 4:28:49 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing log4j from [D:\springsource\vfabric-tc-server-developer-2.9.5.SR1\base-instance\wtpwebapps\myApp\WEB-INF\config\log4j.xml]
log4j: Trying to find [log4j.xml] using context classloader WebappClassLoader
context: /myApp
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1e6cecc
.
log4j: Trying to find [log4j.xml] using WebappClassLoader
context: /myApp
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1e6cecc
class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader WebappClassLoader
context: /myApp
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1e6cecc
.
log4j: Trying to find [log4j.properties] using WebappClassLoader
context: /myApp
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1e6cecc
class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
log4j: System property is :null
log4j: Standard DocumentBuilderFactory search succeded.
log4j: DocumentBuilderFactory is: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
log4j: debug attribute= "true".
log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Level value for root is [INFO].
log4j: root level set to INFO
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Setting property [target] to [System.out].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j:WARN No such property [treshold] in org.apache.log4j.ConsoleAppender.
log4j: Setting property [conversionPattern] to [%d{HH:mm:ss} %c{1}:%L - %m%n].
log4j: Adding appender named [console] to category [root].
log4j: Class name: [org.apache.log4j.RollingFileAppender]
log4j: Setting property [file] to [C:\Users\myUsername/myApp.log].
log4j: Setting property [maxFileSize] to [5MB].
log4j: Setting property [maxBackupIndex] to [50].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n].
log4j: setFile called: C:\Users\myUsername/myApp.log, true
log4j: setFile ended
log4j: Adding appender named [file] to category [root].
我的配置文件位于WEB-INF\config\log4j.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC
"-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Console Appender -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Treshold" value="ERROR"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="myApp %d{HH:mm:ss} %c{1}:%L - %m%n" />
</layout>
</appender>
<!-- File Appender -->
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${user.home}/myApp.log"/>
<param name="MaxFileSize" value="5MB"/>
<param name="MaxBackupIndex" value="50"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<!-- Root Logger -->
<root>
<level value="INFO" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</root>
</log4j:configuration>
显然,log4j找到conf文件......最终......但为什么它仍然将所有调试信息吐出到Spring控制台(当我使用tomcat启动我的应用程序时catalina.out)?
谢谢,任何帮助都非常受欢迎。 干杯!