log4j2.properties每日翻转不起作用

时间:2017-09-14 14:05:36

标签: elasticsearch logging log4j2

我想以下列方式更改ElasticSearch的log4j2配置。来自ElasticSearch的日志应保存在目录中:/path/to/log/{year}/{month}/{day}/cluster_name.log但TimeBasedTriggeringPolicy仅在一天结束后才进行翻转。我一直在尝试使用TimeBasedRollingPolicy,但无法通过* .properties文件进行配置。我将整个log4j2.properties重写为log4j2.xml文件,但ElasticSearch需要log4j2.properites。最后,我决定辞去将letter-day的日志记录到适当的目录。我回到了TimeBasedTriggeringPolicy,我使用了这个filePattern /path/to/log/%d{yyyy/MM/dd}/cluster_name.log,但仍然无效。

配置文件的大部分内容:

appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = /path/to/log/cluster_name.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n
appender.rolling.filePattern = /path/to/log/%d{yyyy/MM/dd}/cluster_name.log
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true

1 个答案:

答案 0 :(得分:0)

我认为%d{yyyy/MM/dd}模式将创建名称为2017/09/19的目录,这是无效的目录名称。这就是原因,它没有用。

请尝试以下filePattern -

appender.rolling.filePattern = /path/to/log/$${date:yyyy}/$${date:MM}/$${date:dd}/cluster_name_%d{yyyy-MM-dd}.log

它会像下面那样旋转日志文件 -

  

/路径/到/日志/ {每年} / {月} / {}天/ cluster_name_ {日期和时间} .LOG

在文件名中提供日期是强制性的。没有它,它可能无法正常工作。