Here is my log4j.properties
file
# Set loggers' levels
log4j.rootLogger=warn, trace_file
# Appender
log4j.appender.trace_file=org.apache.log4j.RollingFileAppender
log4j.appender.trace_file.Append=true
log4j.appender.trace_file.File=log/myLog.log
log4j.appender.trace_file.MaxFileSize=10MB
log4j.appender.trace_file.MaxBackupIndex=50
# PatternLayout
log4j.appender.trace_file.layout=org.apache.log4j.PatternLayout
log4j.appender.trace_file.layout.ConversionPattern=%d [%p] (%F:%L) %m%n
# Classes
log4j.logger.my_package=info, trace_file
What I want :
my.package
in trace_file
with at least INFO
leveltrace_file
ONLY if it's at least WARN
level My configuration does'nt work. If my.package
raises a log request of level WARN
, this log request gets written two times. If I use two separate appenders, there is no problem.
What am I missing ?
Try removing the "trace_file" directive from the my_package logger statement.
Change
log4j.logger.my_package=info, trace_file
to
log4j.logger.my_package=info
Appenders are inherited from the parent logger by default, so by specifying trace_file
for both root logger and the my_package
, you're telling it to do it twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With