Logback追加程序将消息作为HTTP消息发布 [英] Logback appender to post message as HTTP message
问题描述
根据我的要求,我只想将HTTP消息发布到org.slf4j.LoggerFactory.getLogger()
记录的另一端.
As per my requirement I just wanted to post HTTP message to other end which is logged by org.slf4j.LoggerFactory.getLogger()
.
在INFO level
处记录的以下JSON字符串.
The following JSON string logged at INFO level
.
{
"studentName": "My Name",
"Deratment": "Computer Science",
"address": {
"Address Line1": "My Address Line1",
"Address Line2": "My Address Line2",
"Address Line3": "My Address Line3"
}
}
注意事项
-
Http消息应以MIME类型
application/json
应该仅处理INFO
级别中的特定日志,而不是全部.
should process only the particular log in INFO
level not all.
Logback中是否有内置的附加器来实现这一目标?
Is there any built-in appender in Logback to achieve this?
如果没有,什么是最好的方法?
If not, what is the best way to do it?
推荐答案
Logback works really well with logstash: https://github.com/logstash/logstash-logback-encoder.
第一步是将logback配置为logstash连接.
First step would be to configure logback to logstash connection.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:4560</destination>
<!-- encoder is required -->
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<root level="DEBUG">
<appender-ref ref="stash" />
</root>
</configuration>
完成后,您需要创建一条从tcp输入到http输出插件的管道,如下所示
Once it is done, you would need to create a pipeline from tcp input to http output plugin that may look as follows
input {
tcp {
port => 4560
codec => json_lines
}
}
output {
http {
http_method => ...
url => ...
}
}
(请参阅 https://www.elastic .co/guide/zh-CN/logstash/current/plugins-outputs-http.html )
这篇关于Logback追加程序将消息作为HTTP消息发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!