Log4j不使用log4j.properties创建任何文件

时间:2013-11-03 21:46:08

标签: java logging

我在使用log4j.properties创建日志文件时遇到问题。文件未生成。无论我尝试什么。这是Tomcat的日志:

INFO: Initializing log4j from [/usr/share/tomcat7/webapps/Money/WEB-INF/classes /log4j.properties]
lis 03, 2013 10:37:29 PM org.apache.catalina.core.ApplicationContext log

的web.xml

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <context-param>
        <param-name>log4jRefreshInterval</param-name>
        <param-value>10000</param-value>
    </context-param>

log4j.properties

# Root logger option
log4j.debug=true
log4j.rootLogger=DEBUG, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logs/money.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

以下是我使用记录器的方式:

private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);

并且即:

LOGGER.debug("Finding user by email FAILED");

1 个答案:

答案 0 :(得分:0)

解决方案是添加catalina.home变量:

log4j.appender.file.File=${catalina.home}/logs/money.log