3

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.

  1. is my observation correct or am I missing something ?
  2. how should I alter the configuration in order to achieve only ERROR level loggings in server.log?
4

1 回答 1

3

类别的级别决定是否记录或丢弃源自该类别的事件;它对从子类别接收到的事件没有任何过滤效果。

由于GeneraPurpose.classTypes级别为INFO,任何不严重的事件INFO都将被丢弃,但其余的将被保留。

由于GeneralPurpose.classTypes具有可加性true,启用的事件将被传递到其在层次结构中的父类别——特别是包括GeneralPurpose.

由于未在 上设置阈值webAppLogger,因此它将记录它接收到的所有事件。

由于未在 上设置阈值defaultLogger,因此它将记录它接收到的所有事件。

如果您希望defaultLogger仅包含ERROR事件或更糟,请将其阈值设置为ERROR

于 2012-04-09T23:25:13.180 回答