?
Solved

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

Posted on 2006-04-12
5
Medium Priority
?
10,180 Views
Last Modified: 2008-01-09
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
Comment
Question by:daryn
  • 3
5 Comments
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16435193
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
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16435219
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
 
LVL 92

Assisted Solution

by:objects
objects earned 280 total points
ID: 16441110
Don't believe you can, you can either roll on size *or* roll daily.
0
 
LVL 11

Accepted Solution

by:
WelkinMaze earned 600 total points
ID: 16441174
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
 

Author Comment

by:daryn
ID: 16472301
thanks guys
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question