log4j2属性为控制台和文件设置了不同的阈值

时间:2019-02-08 15:06:55

标签: java spring log4j log4j2

我想为仅日志错误设置控制台阈值,并为信息级别的文件鉴赏器设置阈值。

status = info
name= properties_configuration

property.basePath = C:\\

appender.console.type = Console
appender.console.name = consoleLogger
appender.console.target = SYSTEM_OUT
appender.console.layout.type = PatternLayout
appender.console.threshold=ERROR

appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c] [%M] [%l] - %msg%n

appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName= ${basePath}my.log
appender.rolling.filePattern= ${basePath}my_%d{yyyyMMdd}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c] [%M] [%l] - %msg%n

appender.rolling.policies.type = Policies

appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.delete.type = Delete
appender.rolling.strategy.delete.basePath = ${basePath}
appender.rolling.strategy.delete.maxDepth = 1
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
appender.rolling.strategy.delete.ifLastModified.age = 1d

rootLogger.level = info
rootLogger.additivity = false
rootLogger.appenderRef.rolling.ref = fileLogger
rootLogger.appenderRef.console.ref = consoleLogger

我设置了阈值,但信息级别已登录到文件中,也已登录到控制台中。

怎么了? 谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用过滤器来设置控制台附加程序,使其不记录以下错误级别。

appender.console.filter.threshold.type = ThresholdFilter
appender.console.filter.threshold.level = error