1. 程式人生 > >ES Log4J配置資訊

ES Log4J配置資訊

# 配置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