# 配置RollingFileappender
appender.rolling.type = RollingFile
appender.rolling.name = rolling
# 日志名稱 /var/log/elasticsearch/production.log
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n
# 滾動日志到/var/log/elasticsearch/production-yyyy-MM-dd-i.log; 日志將被壓縮在每個滾動,i並將增加
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz
appender.rolling.policies.type = Policies
# 使用基於時間的滾動策略
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
# 每天滾動日志
appender.rolling.policies.time.interval = 1
# 在日邊界上對齊滾動(而不是每24小時滾動一次)
appender.rolling.policies.time.modulate = true
# 使用基於文件大小的滾動策略,比如文件到了100M
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
# 文件大小在256 MB之后滾動日志
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
# 壓縮日志上的大小條件是2 GB
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB
如果要在指定的時間段內保留日志文件,則可以使用帶有刪除操作的滾動策略。
# 配置 DefaultRolloverStrategy
appender.rolling.strategy.type = DefaultRolloverStrategy
# 配置Delete處理滾動的動作
appender.rolling.strategy.action.type = Delete
# Elasticsearch日志的基本路徑
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
# 處理滾動時應用的條件
appender.rolling.strategy.action.condition.type = IfFileName
# 從與glob匹配的基本路徑中刪除文件 ${sys:es.logs.cluster_name}-*; 這是日志文件滾動到的glob; 只需要刪除滾動的Elasticsearch日志,而不是刪除棄用和慢日志
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-*
# 嵌套的條件適用於與glob匹配的文件
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified
# 保留七天的日志
appender.rolling.strategy.action.condition.nested_condition.age = 7D
原文鏈接:https://blog.csdn.net/qq_21383435/article/details/79295329
