log4j日志文件未更新

时间:2015-01-05 05:20:18

标签: java tomcat log4j

我在Tomacat中运行的maven框架中有一个Java spring应用程序。

IDE:Eclipse

创建 log4j.properties file 并将其放在名为“log”的文件夹中。右键单击日志文件夹。

Selected 'Build Path --> Use as source folder'

以下是 log4j.properties

log = /log4j
log4j.rootLogger = DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n

这是我记录

的方式
static Logger log = Logger.getLogger(Sample.class.getName());
log.info("sample");

我的问题是

1. While maven install, log file created in D:\log4j\log.out
2. I deleted the file. then run the application
3. Now file created. But no content. Its size is 0 KB.
4. When I stop the application, the file is updated with the content.

我错在哪里?

1 个答案:

答案 0 :(得分:2)

没错,你的日志工作正常。日志文件已缓冲。

请参阅How do you flush a buffered log4j FileAppender?