| Author |
Log4j log file no getting rolled over at the end of the day
|
ravi pathak
Greenhorn
Joined: Jan 05, 2009
Posts: 4
|
|
Hi Friends,
I am using DailyRollingFileAppender to make a log file for a specific logger.
Below is a part of my log file.
# dailyLog is the DailyRollingFileAppender.
log4j.logger.daily.com.XXX.YYY.Process.ProcessManager=dailyLog
log4j.additivity.daily.com.XXX.YYY.Process.ProcessManager=false
log4j.appender.dailyLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.dailyLog.Threshold=debug
log4j.appender.dailyLog.File=\logs/DailyReport/DailyReport.log
log4j.appender.dailyLog.append = true
log4j.appender.dailyLog.DatePattern='.'yyyy-MM-dd
log4j.appender.dailyLog.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyLog.layout.ConversionPattern=%d[%t] %-5p %c - %m%n
with this log file i am able to create a log file but the next day, when running the application the following error occurs and no new log file is created.
java.lang.NullPointerException
at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:292)
at org.apache.log4j.DailyRollingFileAppender.subAppend(DailyRollingFileAppender.java:343)
at org.apache.log4j.WriterAppender.append(WriterAppender.java:150)
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:221)
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:57)
at org.apache.log4j.Category.callAppenders(Category.java:190)
at org.apache.log4j.Category.forcedLog(Category.java:375)
at org.apache.log4j.Category.info(Category.java:696)
If i delete the log file of the previous day, the application works fine, but in presence of previous' day log file, no rolling of file takes place.
Please help me in figuring out what i am missing.
Thanks.
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
Note: I'm being ultra lazy and not even looking at the Log4j docs
Is it being caused by:
log4j.appender.dailyLog.File=\logs/DailyReport/DailyReport.log
Where you have back and forward slashes intermixed?
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
ravi pathak
Greenhorn
Joined: Jan 05, 2009
Posts: 4
|
|
Thanks for the reply, Martijn
But, this configuration of slashes works , if there is no preexisting log file in the directory. when there is a file already in this folder, the above mentioned error occurs.
|
 |
ravi pathak
Greenhorn
Joined: Jan 05, 2009
Posts: 4
|
|
just wanted to specify 1 more thing.
In the log4j.properties file, the above mentioned error comes when
i have not set the "rootlogger" to the "dailyLog" logger.
when i set the rootlogger to 'dailyLog', the log file gets rolled over in presence of a preexisting log file.
can this have an impact on the rolling over of files ?
But since i want this log file (logger) to be different from other loggers, i cant afford to set the rootlogger.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
This is Windows, right? Yeah, it doesn't work because of something like this: the file doesn't get closed, so Windows has a lock on it, so it can't be renamed. I tried to fix the appender to close the file properly but in the end I found a thing called DatedFileAppender and used that instead.
Works fine on other operating systems though.
|
 |
ravi pathak
Greenhorn
Joined: Jan 05, 2009
Posts: 4
|
|
Thanks Paul, your suggestion worked.
But i wonder if this DailyRollingFileAppender does not work properly, why is it used widely ...
|
 |
 |
|
|
subject: Log4j log file no getting rolled over at the end of the day
|
|
|