2017-07-02 140 views
0

我是Log4j2的新手,我無法理解如何在兩個appender中設置兩個不同的級別,例如我想在File.log以上級別Error中寫入,並且在控制檯級別Debug之後,這裏是我的屬性文件:兩個appender中的不同級別log4j2.properties?

status = error 
name = PropertiesConfig 

property.filename = logs 

appenders = console, rolling 

appender.console.type = Console 
appender.console.name = STDOUT 
appender.console.layout.type = PatternLayout 
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n 

appender.rolling.type = RollingFile 
appender.rolling.name = RollingFile 
appender.rolling.fileName = ${filename}/AndrewDebug-${date:yyyy-MM-dd}.log 
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz 
appender.rolling.layout.type = PatternLayout 
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%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.policies.size.type = SizeBasedTriggeringPolicy 
appender.rolling.policies.size.size=10MB 
appender.rolling.strategy.type = DefaultRolloverStrategy 
appender.rolling.strategy.max = 20 

logger.rolling.name = web.languages 
logger.rolling.level = debug 
logger.rolling.appenderRef.rolling.ref = RollingFile 

rootLogger.level = debug 
rootLogger.appenderRefs = stdout 
rootLogger.appenderRef.stdout.ref = STDOUT 
+0

你嘗試使用logger.console.level =調試? – abstractnature

+0

org.apache.logging.log4j.core.config.ConfigurationException:爲記錄器控制檯提供沒有名稱屬性 –

回答

0

使用

logger.console.level = debug 
logger.rolling.level = info 

編輯:定義一個名字也

logger.console.name = web.languages 
logger.console.appenderRef.console.ref = STDOUT 
+0

嗨,我得到了這個,org.apache.logging.log4j.core.config.ConfigurationException:沒有爲記錄器控制檯提供名稱屬性 –

相關問題