• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10334
  • Last Modified:

daily log rotation in log4j.properties file.. help!

hi there..

I have no knowledge of java programming (lets make that clear from the outset :).

I've been told to change this file:

log4j.rootLogger=debug, stdout, file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=/logs/blah.log

log4j.appender.file.MaxFileSize=100KB
# Keep one backup file
log4j.appender.file.MaxBackupIndex=10

log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%p - %m%n


to ensure that the file goes for about 50MB max and is then renamed at the end of the day to blah.log.yyyy-mm-dd.

I have absolutely no idea how to do this and the log4j documentation at apache doesnt seem to help much.

Any ideas please?

thanks in advance for any help.

Daryn
0
daryn
Asked:
daryn
  • 3
2 Solutions
 
WelkinMazeCommented:
Hi,

Replace these rows:

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=/logs/blah.log

log4j.appender.file.MaxFileSize=100KB


with the following:


log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=/logs/blah.log
log4j.appender.file.MaxFileSize=51200KB

0
 
WelkinMazeCommented:
Also remove this from your file:

# Keep one backup file
log4j.appender.file.MaxBackupIndex=10


So here's the file with the replacements:


log4j.rootLogger=debug, stdout, file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=/logs/blah.log
log4j.appender.file.MaxFileSize=51200KB

log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%p - %m%n


0
 
objectsCommented:
Don't believe you can, you can either roll on size *or* roll daily.
0
 
WelkinMazeCommented:
Yeap,
I suppose it's better to choose directly one of the following:

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=/logs/blah.log

or

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/logs/blah.log
log4j.appender.file.MaxFileSize=51200KB
# Keep one backup file
log4j.appender.file.MaxBackupIndex=10
0
 
darynAuthor Commented:
thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now