• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Log4j log file no getting rolled over at the end of the day

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
ravi pathak
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Sheriff
Posts: 28368
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul, your suggestion worked.
But i wonder if this DailyRollingFileAppender does not work properly, why is it used widely ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic