当前位置: 首页 > 工具软件 > M-LOG > 使用案例 >

ES配置文件之日志-log4j2.properties

薛宏壮
2023-12-01

说明

仅以此文简单介绍下ES配置文件中,如何配置日志文件。

配置文件中各参数含义,可查看文章:

ES安装路径:/home/es/software/elasticsearch

ES日志配置文件路径:/home/es/software/config/es-xxx[es集群名称]/log4j2.properties

ES版本:V_5.4.2

ES日志类型:集群日志、慢日志(查询慢日志&写入慢日志)、deprecation日志

log4j2.properties 配置

# 5.4 版本 ES log4j 配置介绍
# 参考 ES 官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/settings.html

status = error

# log action execution errors for easier debugging
logger.action.name = org.elasticsearch.action
logger.action.level = debug

appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{ISO8601} %p [%t] %c - %m%n

# 配置 RollingFile 附加器
appender.rolling.type = RollingFile
# 集群日志的 appender 标签名称
appender.rolling.name = rolling
# 日志输出路径:/home/es/logs/es/XX[集群名称]-cluster.log (路径从 elasticsearch.yml 配置文件中获取)
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-cluster.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{ISO8601} %p [%t] %c:%M:%L - %m%n
# 将日志滚动到 /home/es/logs/es/XX[集群名称]-yyyy-MM-dd-%i.log
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log
appender.rolling.policies.type = Policies
# 使用基于时间的滚动策略
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
# 每天滚动日志
appender.rolling.policies.time.interval = 1
# 在天数边界上对齐滚动(而不是每24h滚动一次)
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
# 日志文件每达到 1GB 大小进行一次滚动
appender.rolling.policies.size.size = 1GB
# 当天日志文件最多保留 3 个
appender.rolling.strategy.max = 3
# 配置 DefaultRolloverStrategy 
appender.rolling.strategy.type = DefaultRolloverStrategy
# 配置 Delete 用于处理翻转操作
appender.rolling.strategy.action.type = Delete
# ES日志基本路径
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
# 如果超过指定天数的文件,则仅删除5天以上的文件
appender.rolling.strategy.action.condition.type = IfFileName
# 从与 glob 匹配的基本路径中删除文件 ${sys:es.logs.cluster_name}-*;这是日志文件滚动到的位置;仅删除滚动的es集群日志,而不删除其他日志时才需要这样做
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-*
# 处理过渡时适用的条件
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified
# 日志保留5天
appender.rolling.strategy.action.condition.nested_condition.age = 5D


rootLogger.level = info
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.rolling.ref = rolling

# 可以加载多个配置文件(在这种情况下,它们将被合并),只要它们被命名 log4j2.properties 并将 Elasticsearch config 目录作为祖先即可
appender.deprecation_rolling.type = RollingFile
# deprecation 日志的 appender 标签名称
appender.deprecation_rolling.name = deprecation_rolling
# deprecation 日志路径和日志格式
appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log
appender.deprecation_rolling.layout.type = PatternLayout
appender.deprecation_rolling.layout.pattern = %d{ISO8601} %p [%t] %c:%M:%L - %m%n
# If you append .gz or .zip to appender.rolling.filePattern, then the logs will be compressed as they are rolled.
appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%d{yyyy-MM-dd}-%i.log.gz
appender.deprecation_rolling.policies.type = Policies
appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.deprecation_rolling.policies.size.size = 1GB
appender.deprecation_rolling.strategy.max = 3
appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy
appender.deprecation_rolling.strategy.action.type = Delete
appender.deprecation_rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.deprecation_rolling.strategy.action.condition.type = IfFileName
# 从与 glob 匹配的基本路径中删除文件 ${sys:es.logs.cluster_name}_deprecation-*;
appender.deprecation_rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}_deprecation-*
appender.deprecation_rolling.strategy.action.condition.nested_condition.type = IfLastModified
appender.deprecation_rolling.strategy.action.condition.nested_condition.age = 5D

logger.deprecation.name = org.elasticsearch.deprecation
logger.deprecation.level = warn
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling
logger.deprecation.additivity = false

appender.index_search_slowlog_rolling.type = RollingFile
# index_search_slowlog 查询慢日志的 appender 标签名称
appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling
# index_search_slowlog 查询慢日志路径和日志格式
appender.index_search_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog.log
appender.index_search_slowlog_rolling.layout.type = PatternLayout
appender.index_search_slowlog_rolling.layout.pattern = %d{ISO8601} %p [%t] %c:%M:%L - %m%n
appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog-%d{yyyy-MM-dd}-%i.log
appender.index_search_slowlog_rolling.policies.type = Policies
appender.index_search_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.index_search_slowlog_rolling.policies.time.interval = 1
appender.index_search_slowlog_rolling.policies.time.modulate = true
appender.index_search_slowlog_rolling.strategy.max = 3
appender.index_search_slowlog_rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.index_search_slowlog_rolling.policies.size.size = 1GB
appender.index_search_slowlog_rolling.strategy.type = DefaultRolloverStrategy
appender.index_search_slowlog_rolling.strategy.action.type = Delete
appender.index_search_slowlog_rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.index_search_slowlog_rolling.strategy.action.condition.type = IfFileName
# 从与 glob 匹配的基本路径中删除文件 ${sys:es.logs.cluster_name}_index_search_slowlog-*
appender.index_search_slowlog_rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}_index_search_slowlog-*
appender.index_search_slowlog_rolling.strategy.action.condition.nested_condition.type = IfLastModified
appender.index_search_slowlog_rolling.strategy.action.condition.nested_condition.age = 5D

logger.index_search_slowlog_rolling.name = index.search.slowlog
logger.index_search_slowlog_rolling.level = trace
logger.index_search_slowlog_rolling.appenderRef.index_search_slowlog_rolling.ref = index_search_slowlog_rolling
logger.index_search_slowlog_rolling.additivity = false

appender.index_indexing_slowlog_rolling.type = RollingFile
# index_indexing_slowlog 写入慢日志的 appender 标签名称
appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling
# index_indexing_slowlog 写入慢日志路径和日志格式
appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog.log
appender.index_indexing_slowlog_rolling.layout.type = PatternLayout
appender.index_indexing_slowlog_rolling.layout.pattern = %d{ISO8601} %p [%t] %c:%M:%L - %m%n
appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog-%d{yyyy-MM-dd}-%i.log
appender.index_indexing_slowlog_rolling.policies.type = Policies
appender.index_indexing_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.index_indexing_slowlog_rolling.policies.time.interval = 1
appender.index_indexing_slowlog_rolling.policies.time.modulate = true
appender.index_indexing_slowlog_rolling.strategy.type = DefaultRolloverStrategy
appender.index_indexing_slowlog_rolling.strategy.max = 3
appender.index_indexing_slowlog_rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.index_indexing_slowlog_rolling.policies.size.size = 1GB
appender.index_indexing_slowlog_rolling.strategy.type = DefaultRolloverStrategy
appender.index_indexing_slowlog_rolling.strategy.action.type = Delete
appender.index_indexing_slowlog_rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.index_indexing_slowlog_rolling.strategy.action.condition.type = IfFileName
# 从与 glob 匹配的基本路径中删除文件 ${sys:es.logs.cluster_name}_index_indexing_slowlog-*
appender.index_indexing_slowlog_rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}_index_indexing_slowlog-*
appender.index_indexing_slowlog_rolling.strategy.action.condition.nested_condition.type = IfLastModified
appender.index_indexing_slowlog_rolling.strategy.action.condition.nested_condition.age = 5D

logger.index_indexing_slowlog.name = index.indexing.slowlog.index
logger.index_indexing_slowlog.level = trace
logger.index_indexing_slowlog.appenderRef.index_indexing_slowlog_rolling.ref = index_indexing_slowlog_rolling
logger.index_indexing_slowlog.additivity = false

 类似资料: