log4j2日志文件中没有条目

时间:2018-03-05 15:58:20

标签: java log4j2

当我运行我的代码时,会生成日志文件,但没有条目。 我做错了什么?

在java中,我像这样实例化记录器:

static Logger log = LogManager.getRootLogger();

这是我的属性文件:

status = error
name = PropertiesConfig
dest = C:\\Logs\\cds_import_logs\\cs_import.log
#Make sure to change log file path as per your need
property.filename = C:\\Logs\\cds_import_logs\\cs_import.log

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = all

appenders = rolling

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
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

loggers = rolling

#Make sure to change the package structure as per your application
logger.rolling.name = com.howtodoinjava
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile

1 个答案:

答案 0 :(得分:0)

更改

static Logger log = LogManager.getRootLogger();

static Logger log = LogManager.getLogger(YOUR_CLASS_NAME.class.getName());

我测试了它并且有效。

另外,请确保您在下面的行中有正确的包名(而不是com.howtotodoinjava):

logger.rolling.name = com.howtodoinjava