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
darynAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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


Mick BarryJava DeveloperCommented:
Don't believe you can, you can either roll on size *or* roll daily.
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
darynAuthor Commented:
thanks guys
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.