gpt4 book ai didi

elasticsearch - Logstash Logback编码器,Logstash转发器和Logstash

转载 作者:行者123 更新时间:2023-12-02 23:35:01 25 4
gpt4 key购买 nike

我不喜欢https://blog.codecentric.de/en/2014/10/log-management-spring-boot-applications-logstash-elastichsearch-kibana/的建议,我已经设置了logstash编码器和logstash转发器,以将所有内容推送到我的logstash守护进程中,并最终在ElasticSearch中建立索引。

这是我的配置:

logstash.xml

<included>
<include resource="org/springframework/boot/logging/logback/base.xml"/>

<property name="FILE_LOGSTASH" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}.json"/>
<appender name="LOGSTASH"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${FILE_LOGSTASH}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${FILE_LOGSTASH}.%i</fileNamePattern>
</rollingPolicy>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerInfo>true</includeCallerInfo>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="LOGSTASH"/>
</root>
</included>

logstash-forwarder.conf
{
"network": {
"servers": [
"logstash:5043"
],
"ssl certificate": "/etc/pki/tls/certs/logstash-forwarder/logstash-forwarder.crt",
"ssl key": "/etc/pki/tls/private/logstash-forwarder/logstash-forwarder.key",
"ssl ca": "/etc/pki/tls/certs/logstash-forwarder/logstash-forwarder.crt",
"timeout": 15
},
"files": [
{
"paths": [
"${ENV_SERVICE_LOG}/*.log.json"
],
"fields": {
"type": "${ENV_SERVICE_NAME}"
}
}
]
}

logstash.conf
input {
lumberjack {
port => 5043

ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder/logstash-forwarder.key"
}
}

output {
elasticsearch { host => "localhost" }
}

一切正常,日志被保存在ElasticSearch中。

在这一点上,我希望能够指定其他要由ElasticSearch索引的字段,例如日志级别。在@message内容中搜索是否存在错误或警告不是很有用。

我怎样才能做到这一点?我应该更改哪种配置以使级别在ElasticSearch中显示为索引字段?

最佳答案

您正在寻找的是logstash过滤器,该过滤器将在索引器上用作输入和输出节的对等体。

有很多过滤器(请参阅the doc),但是您可以使用grok{}将正则表达式应用于消息字段并提取日志级别。

您没有包括示例消息,但是,给定类似“foo 123 bar”的字符串,此模式会将“123”提取到一个名为loglevel的整数字段中:

grok {
match => ["message", "foo %{NUMBER:loglevel:int} bar"]
}

关于在网络上编写粗俗模式的信息很多。尝试 this one

关于elasticsearch - Logstash Logback编码器,Logstash转发器和Logstash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32316044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com