We help IT Professionals succeed at work.

How to use log4j with appending more log messages

West100
West100 asked
on
How should a log4j properties file be configured so that messages won't be appended for each run to the same log file? Currently weeks worth of logged messages have been rolled into the same log file making it huge and difficult to work with.  I want to have a fresh log file containing only the current runs logged messages. I don't want separate logs for each run. One log is enough containing one runs worth of messages at a time.

I am currently using the following log4j.properties file configurations:
log4j.rootLogger = INFO, F
log4j.appender.F=org.apache.log4j.FileAppender
log4j.appender.F.File=/usr/local/admin/logs/QASBulk.log
log4j.appender.F.layout=org.apache.log4j.PatternLayout
log4j.appender.F.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] (%-5p) - %m - at (%F:%L)%n

Thanks

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Try

log4j.appender.F.fileAppend=false

Author

Commented:
No that does not work
CERTIFIED EXPERT
Top Expert 2016
Commented:
Sorry. That should have been

log4j.appender.F.append=false
Also have a look on RollingFileAppender and DailyRollingFileAppender

http://veerasundar.com/blog/2009/07/log4j-tutorial-how-to-send-the-log-messages-to-a-file/
CERTIFIED EXPERT
Top Expert 2016

Commented:
:)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.