Friday, 5 September 2014

How to split logs by package in Log4J

Here an example with properties file
# ---------------------------------------------
#  Logging
# ---------------------------------------------
log4j.appender.SECURITY_FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.SECURITY_FILE.File=${HYBRIS_LOG_DIR}/tomcat/spring-security.log
log4j.appender.SECURITY_FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.SECURITY_FILE.ImmediateFlush=true
log4j.appender.SECURITY_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.SECURITY_FILE.layout.ConversionPattern=%d - %m%n
log4j.appender.SECURITY_FILE.MaxBackupIndex=10
log4j.additivity.org.springframework.security=false
log4j.logger.org.springframework.security=info,SECURITY_FILE
It sends all "info" level logs from the package "org.springframework.security" into the file "spring-security.log".

Try it and let me know!

No comments:

Post a Comment