在我基于Spring 4.1的应用程序中,我没有使用任何web.xml。如何在我的应用程序中不使用web.xml来初始化log4j?我碰到this SO问题,它通过web.xml建议所需的配置,但我不知道如何通过代码来完成。在没有web.xml的情况下使用spring 4.1初始化log4j
。我已经把我的log4j.properties在WEB-INF/lib文件夹,它看起来像这样:
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.category.org.springframework.beans.factory=DEBUG
的log4j-1.2.17.jar也是WEB-INF/lib文件夹。但出现在启动时出现以下消息:
的log4j:警告没有附加目的地可以为记录器 (org.springframework.web.context.support.StandardServletEnvironment)中找到。 log4j:WARN请正确初始化log4j系统。
请大家帮忙。
你试过把log4j.properties放入src/main/resources目录而不是WEB-INF/lib? – freakman 2014-10-20 08:47:21