Elasticsearch7.x中文教程翻译(十四): 日志配置
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
################################################