Reputation: 8498
I have a Java spring application in maven framework running in Tomacat.
IDE: Eclipse
Created a log4j.properties file
and put it in a folder called 'log'. Right clicked on the log folder.
Selected 'Build Path --> Use as source folder'
Below given is my 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
This is the way I followed for logging
static Logger log = Logger.getLogger(Sample.class.getName());
log.info("sample");
My issue is
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.
Where am I mistaken?
Upvotes: 1
Views: 2857
Reputation: 5569
No mistake, your log is working fine. The log file is buffered.
See How do you flush a buffered log4j FileAppender?.
Upvotes: 2