log4j: routing logs to multiple files based on log levels


Sample log4j.properties to route logs of same app to multiple files – one ideally less verbose that can be shared with customer/to know status quickly, the other one verbose/exhaustive.

Logging framework: Apache log4j 1.12.16

log4j.rootLogger=DEBUG, logfile, detaillogfile

# less verbose log with a threshold of INFO
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.Threshold=INFO
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=[%d] %m 
log4j.appender.logfile.File=logs/mylogfile.log

# no threshold specified; so, all >debug logs go here
log4j.appender.detaillogfile=org.apache.log4j.RollingFileAppender
log4j.appender.detaillogfile.MaxFileSize=10MB
log4j.appender.detaillogfile.MaxBackupIndex=100
log4j.appender.detaillogfile.layout=org.apache.log4j.PatternLayout
log4j.appender.detaillogfile.layout.ConversionPattern=[%d|%p|%F|%L] %m %n
log4j.appender.detaillogfile.File=detaillogs/mydetaillogfile.log

This can be modified as per your requirements.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: