2013-11-03 54 views
0

我在使用log4j.properties創建日誌文件時遇到問題。文件沒有生成。無論我嘗試什麼。這裏的日誌從Tomcat:Log4j不使用log4j.properties創建任何文件

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

嘗試日誌路徑設置爲$ {} catalina.base /logs/money.log。你在使用什麼操作系統? – Boj

回答

0

解決的辦法是添加的catalina.home變量:

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