我在 JBoss 7.1.1.FINAL 中使用 log4j 创建了一个 spring 应用程序,这是我的 log4j 配置:
# Log4j level and names.
log4j.rootLogger=INFO, stdout, fileAppender
# Log4j relative path.
dir=${myWebapp-instance-root}
file=WEB-INF/logs/app.log
target=${dir}/${file}
# Used only for development.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p (%F\:%L) \u2013 %m%n
log4j.logger.net.sf.ehcache=TRACE
# Log4j internal message debug , only on console .
log4j.debug=true
# File appender used in production.
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
#log4j.appender.fileAppender.File=${app.logdir}/app.log
log4j.appender.fileAppender.File=${target}
log4j.appender.fileAppender.MaxFileSize=1MB
log4j.appender.fileAppender.MaxBackupIndex=5
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d{ISO8601} %t %p %c \u2013 %m%n
目录和文件已创建,但在 app.log 中没有任何内容(白色页面) Jboss 在运行应用程序时不会给出任何错误,这是 log4j 的一部分:
17:01:33,342 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/projvehimerc]] (MSC service thread 1-1) Initializing log4j from [/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/log4j-webapp.properties]
17:01:33,351 INFO [stdout] (MSC service thread 1-1) log4j: Parsing for [root] with value=[INFO, stdout, fileAppender].
17:01:33,352 INFO [stdout] (MSC service thread 1-1) log4j: Level token is [INFO].
17:01:33,354 INFO [stdout] (MSC service thread 1-1) log4j: Category root set to null
17:01:33,355 INFO [stdout] (MSC service thread 1-1) log4j: Parsing appender named "stdout".
17:01:33,367 INFO [stdout] (MSC service thread 1-1) log4j: Parsing layout options for "stdout".
17:01:33,414 INFO [stdout] (MSC service thread 1-1) log4j: Setting property [conversionPattern] to [%d{ISO8601} [%t] %-5p (%F:%L) – %m%n].
17:01:33,416 INFO [stdout] (MSC service thread 1-1) log4j: End of parsing for "stdout".
17:01:33,417 INFO [stdout] (MSC service thread 1-1) log4j: Parsed "stdout" options.
17:01:33,418 INFO [stdout] (MSC service thread 1-1) log4j: Parsing appender named "fileAppender".
17:01:33,421 INFO [stdout] (MSC service thread 1-1) log4j: Parsing layout options for "fileAppender".
17:01:33,422 INFO [stdout] (MSC service thread 1-1) log4j: Setting property [conversionPattern] to [%d{ISO8601} %t %p %c – %m%n].
17:01:33,423 INFO [stdout] (MSC service thread 1-1) log4j: End of parsing for "fileAppender".
17:01:33,429 INFO [stdout] (MSC service thread 1-1) log4j: Setting property [file] to [/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war//WEB-INF/logs/app.log].
17:01:33,430 INFO [stdout] (MSC service thread 1-1) log4j: Setting property [maxBackupIndex] to [5].
17:01:33,430 INFO [stdout] (MSC service thread 1-1) log4j: Setting property [maxFileSize] to [1MB].
17:01:33,431 INFO [stdout] (MSC service thread 1-1) log4j: setFile called: /opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war//WEB-INF/logs/app.log, true
17:01:33,432 INFO [stdout] (MSC service thread 1-1) log4j: setFile ended
17:01:33,432 INFO [stdout] (MSC service thread 1-1) log4j: Parsed "fileAppender" options.
17:01:33,433 INFO [stdout] (MSC service thread 1-1) log4j: Parsing for [net.sf.ehcache] with value=[TRACE].
17:01:33,433 INFO [stdout] (MSC service thread 1-1) log4j: Level token is [TRACE].
17:01:33,433 INFO [stdout] (MSC service thread 1-1) log4j: Category net.sf.ehcache set to null
17:01:33,433 INFO [stdout] (MSC service thread 1-1) log4j: Handling log4j.additivity.net.sf.ehcache=[null]
17:01:33,434 INFO [stdout] (MSC service thread 1-1) log4j: Finished configuring.
以下
17:01:36,680 INFO [stdout] (Finalizer) log4j: Finalizing appender named [stdout].
17:01:36,681 INFO [stdout] (Finalizer) log4j: Finalizing appender named [fileAppender].
就像我说的文件是创建但什么都没有,虽然级别是INFO,为什么?