Log4j additivity, category registration level and application threshold
I'm having trouble understanding the relationship between additivity, category registration level and appender threshold ...
here's the script (log4j.properties file):
log4j.category.GeneralPurpose.classTypes=INFO, webAppLogger
log4j.additivity.GeneralPurpose.classTypes=true
log4j.category.GeneralPurpose=ERROR, defaultLogger
log4j.additivity.GeneralPurpose=false
log4j.appender.webAppLogger=org.apache.log4j.RollingFileAppender
log4j.appender.webAppLogger.File=webapps/someWebApp/logs/webApp.log
log4j.appender.webAppLogger.MaxFileSize=3000KB
log4j.appender.webAppLogger.MaxBackupIndex=10
log4j.appender.webAppLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.webAppLogger.layout.ConversionPattern=%d [%t] (%F:%L) %-5p - %m%n
log4j.appender.webAppLogger.Encoding=UTF-8
log4j.appender.defaultLogger=org.apache.log4j.RollingFileAppender
log4j.appender.defaultLogger.File=logs/server.log
log4j.appender.defaultLogger.MaxFileSize=3000KB
log4j.appender.defaultLogger.MaxBackupIndex=10
log4j.appender.defaultLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.defaultLogger.layout.ConversionPattern=%d [%t] (%F:%L) %-5p - %m%n
log4j.appender.defaultLogger.Encoding=UTF-8
insights: category GeneralPurpose.classTypes - INFO category GeneralPurpose.classTypes has additivity TRUE category GeneralPurpose - ERROR category GeneralPurpose has additivity FALSE
with the current configuration, I would assume the INFO messages posted to the GeneralPurpose.classTypes category. * will only register with the webAppLogger since the parent logger (cateogry) is installed with the ERROR level protocol. However, this is not the case, the message is logged twice (one in each log file). It looks like the ERROR registration level for the parent category is not considered when the event is dispatched as part of additivity ...
- Is my observation correct or am I missing something?
- How do I change the configuration to only reach ERROR level errors in server.log?
thank,
GBA.
source to share
The category level determines whether an event originating from that category is logged or discarded; it has no filtering effect on events received from child categories.
Since it GeneraPurpose.classTypes
has a level INFO
, any events less serious than INFO
that will be discarded, but the remainder will be retained.
Since it GeneralPurpose.classTypes
has additivity true
, included events will be passed on to parent categories in the> hierarchy, specifically including GeneralPurpose
.
Since the threshold is not set to webAppLogger
, it logs all the events it receives.
Since the threshold is not set to defaultLogger
, it will log all the events it receives.
If you want to defaultLogger
include only events ERROR
or worse, set its threshold to ERROR
.
source to share