💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Slow log(慢日志) 原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/index-modules-slowlog.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/index-modules-slowlog.html) 译文链接 : [Slow log(慢日志)](/pages/viewpage.action?pageId=10028543) 贡献者 : @苏涛,[ApacheCN](/display/~apachecn),[Apache中文网](/display/~apachechina) ### 搜索慢日志 分片级慢搜索日志允许将慢搜索(查询和获取阶段)记录到专用日志文件中。 可以为执行的查询阶段和获取阶段设置阈值,这里是一个示例: ``` index.search.slowlog.threshold.query.warn: 10s index.search.slowlog.threshold.query.info: 5s index.search.slowlog.threshold.query.debug: 2s index.search.slowlog.threshold.query.trace: 500ms index.search.slowlog.threshold.fetch.warn: 1s index.search.slowlog.threshold.fetch.info: 800ms index.search.slowlog.threshold.fetch.debug: 500ms index.search.slowlog.threshold.fetch.trace: 200ms ``` ``` 这些设置是动态的,而且可以对每个索引进行设置。 ``` 默认情况下,搜索慢日志没有被启用(设置为-1)。日志级别(warn、info、debug、trace)可以通过给日志分级来控制日志的纪录。不是所有级别的日志都需要纪录,多个级别的好处是能快速对违反特定阀值的日志进行"grep"。 ``` 日志记录在分片级别范围内完成,这意味着在特定分片中执行搜索请求。它不包含整个搜索请求,可以将其广播到几个分片去执行。与请求级别相比,分片级别记录的一些优点是与特定机器上的实际执行关联。 ``` ``` 日志文件默认使用以下配置(在log4j2.properties中可以找到): ``` ``` appender.index_search_slowlog_rolling.type = RollingFile appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling appender.index_search_slowlog_rolling.fileName = ${sys:es.logs}_index_search_slowlog.log appender.index_search_slowlog_rolling.layout.type = PatternLayout appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %.10000m%n appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs}_index_search_slowlog-%d{yyyy-MM-dd}.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 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 ``` ### 索引慢日志 索引慢日志,功能类似于搜索慢日志。日志文件名以_**_index_indexing_slowlog.log**_结尾。日志和阈值的配置方式与搜索慢日志相同。索引慢日志示例: ``` index.indexing.slowlog.threshold.index.warn: 10s index.indexing.slowlog.threshold.index.info: 5s index.indexing.slowlog.threshold.index.debug: 2s index.indexing.slowlog.threshold.index.trace: 500ms index.indexing.slowlog.level: info index.indexing.slowlog.source: 1000 ``` 所有上述设置都是动态的,并且按照索引设置。 默认情况下,Elasticsearch将在慢日志中记录_source的前1000个字符。您可以使用_**index.indexing.slowlog.source**_更改它。将其设置为_**false**_或**_0_**将跳过完全记录源,将其设置为_**true**_将记录整个源,无论大小如何。默认情况下,原始_source将重新格式化,以确保它适合单个日志行。如果保留原始文档格式很重要,您可以通过将_**index.indexing.slowlog.reformat**_设置为_**false**_来关闭重新格式化,这将导致源“按原样”进行记录,并可能跨越多个日志行。 默认情况下,log4j2.properties文件中配置了索引慢日志文件: ``` appender.index_indexing_slowlog_rolling.type = RollingFile appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs}_index_indexing_slowlog.log appender.index_indexing_slowlog_rolling.layout.type = PatternLayout appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.10000m%n appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs}_index_indexing_slowlog-%d{yyyy-MM-dd}.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 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 ```