Reputation: 1006
I'm having trouble understanding the relation between additivity, category logging level and appender threshold.
here's the scenario (my 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 is INFO category GeneralPurpose.classTypes has additivity TRUE category GeneralPurpose is ERROR category GeneralPurpose has additivity FALSE
with the current configuration I would have assumed that INFO messages sent to category GeneralPurpose.classTypes.* would be only logged to webAppLogger since the parent logger (category) is set with ERROR level logging. However, this is not the case, the message is logged twice (one in each log file). Looks like the ERROR logging level for the parent category is not taken into consideration when the event is sent as part of additivity.
Upvotes: 3
Views: 9546
Reputation: 269657
The level of a category determines whether an event originating in that category is logged or discarded; it doesn't have any filtering effect on events that are received from child categories.
Since GeneraPurpose.classTypes
has a level of INFO
, any events less severe than INFO
will be discarded, but the remainder will be preserved.
Since GeneralPurpose.classTypes
has an additivity of true
, enabled events will be passed on to its parent categories in the hierarchy—specifically including GeneralPurpose
.
Since the threshold is not set on the webAppLogger
, it will log all events it receives.
Since the threshold is not set on the defaultLogger
, it will log all events it receives.
If you want the defaultLogger
to include only ERROR
events or worse, set its threshold to ERROR
.
Upvotes: 3