es日志配置,只保存最近3天的日志

Elasticsearch使用Log4j 2进行日志记录。可以使用log4j2.properties文件配置Log4j2。
Elasticsearch公开三个属性

${sys:es.logs.base_path},
${sys:es.logs.cluster_name}
${sys:es.logs.node_name}

可以在配置文件中被引用,以确定日志文件的位置。
该属性${sys:es.logs.base_path}将解析为日志目录,
${sys:es.logs.cluster_name}将解析为群集名称(在默认配置中用作日志文件名的前缀),
${sys:es.logs.node_name}并将解析为节点名称(如果显式设置了节点名称)。

例如,如果你的日志目录(path.logs)是/var/log/elasticsearch和您的群集名为production,然后${sys:es.logs.base_path}将解析/var/log/elasticsearch${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log 将解析/var/log/elasticsearch/production.log

######## Server JSON ############################
appender.rolling.type = RollingFile 
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.json 
appender.rolling.layout.type = ESJsonLayout 
appender.rolling.layout.type_name = server 
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.json.gz 
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 = 256MB 
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.fileIndex = nomax
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.rolling.strategy.action.condition.type = IfFileName 
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize 
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB 

# 若是只保留最近3天的日志,把上面最后两行换成下面这两行
#appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified
#appender.rolling.strategy.action.condition.nested_condition.age = 3D

################################################
posted @ 2020-01-10 15:43  哈喽哈喽111111  阅读(3940)  评论(0编辑  收藏  举报