使用以下配置将消息记录到控制台和文件。我只能看到控制台输出。虽然创建了文件,但它没有任何包含
status = error
name = PropertiesConfig
property.filename = C:/target/rolling/rollingtest.log
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd'T'hh:mm:ss.SSSXXX} %-5p [%t] %x %c %M - %m%n
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = C:/target/rolling2/test1-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd'T'hh:mm:ss.SSSXXX} %-5p [%t] %x %c %M - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 2
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=1KB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 5
logger.rolling.name = com.example.my.app
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT
答案 0 :(得分:1)
我已经测试了你的属性,它们对我来说似乎没问题。请考虑以下事项:
debug
条消息com.example.my.app
开始的完全限定名称的类生成日志消息以下是有效的例子:
package com.example.my.app;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Main {
Logger logger = LogManager.getLogger();
Logger getLogger(){
return logger;
}
public static void main(String[] args) {
Main mainObj = new Main();
mainObj.getLogger().debug("test debig");
}
}