Some log4j tips.

How to ‘override’ instead of ‘append’ to log file:

log4j.appender.LOGFILE.Append=false

How to prevent certain individual logging from passing up to the root logger:

log4j.additivity.MyLogger=false

How to generate html report in log4j:

# logger
log4j.logger.htmlReportLogger=INFO, htmlReport
log4j.additivity.htmlReportLogger=false
# appender
log4j.appender.htmlReport=org.apache.log4j.FileAppender
log4j.appender.htmlReport.File=logs/test_report.html
log4j.appender.htmlReport.layout=org.apache.log4j.HTMLLayout
log4j.appender.htmlReport.layout.Title=Html Test Report
log4j.appender.htmlReport.layout.LocationInfo=true

How to log to rolling file and console:

log4j.rootLogger=INFO, stdout, file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd   HH:mm:ss}   [%c]-[%p]   %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logs/test.log
log4j.appender.file.MaxFileSize=500KB
log4j.appender.file.MaxBackupIndex=5
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd   HH:mm:ss}   [%c]-[%p]   %m%n

References

BACK TO TOP
Post tagged with: log4j, java