使用logstash-logback-编码器记录任意XML结构
我正在使用 logstash-logback-back-encoder 用于记录Java Message的库服务。日志存储在JSON文件中,这些文件已发送到Elasticsearch。到目前为止代码>。但是,有一个新的要求,即还必须记录每个消息的整个XML有效载荷。
假设消息有效负载看起来像这样:
<Message>
<Header source="foo" destination="bar">
<!-- ... -->
</Header>
<Body>
<!-- ... -->
</Body>
</Message>
那么相应的日志条目应采用以下表格:
{
"@timestamp": "2022-05-19T18:07:42.125+01:00",
"@version": "1",
"message": "...",
"level": "DEBUG",
"client_id": "35a81e10-8584-4a9d-bf8c-912a09f4cd0e",
"client_address": "126.111.228.191",
"topic": "foo/bar",
"execution_time": 44,
"status": "SUCCESS",
"payload": {
"Message": {
"Header": {
"@source": "foo",
"@destination": "bar",
"...": "...",
"Body": {
"...": "..."
}
}
}
},
"...": "..."
}
如何有效地实现此输出?
I'm using the logstash-logback-encoder library for logging traffic of a Java messaging service. The logs are stored in JSON files which are sent to Elasticsearch. So far I have been adding extra fields such as client_id
or execution_time
to the log entries using net.logstash.logback.marker.Markers.appendEntries()
. There is, however, a new requirement that the entire XML payload of each message must also be logged.
Suppose a message payload looks like this:
<Message>
<Header source="foo" destination="bar">
<!-- ... -->
</Header>
<Body>
<!-- ... -->
</Body>
</Message>
Then the corresponding log entry should take the following form:
{
"@timestamp": "2022-05-19T18:07:42.125+01:00",
"@version": "1",
"message": "...",
"level": "DEBUG",
"client_id": "35a81e10-8584-4a9d-bf8c-912a09f4cd0e",
"client_address": "126.111.228.191",
"topic": "foo/bar",
"execution_time": 44,
"status": "SUCCESS",
"payload": {
"Message": {
"Header": {
"@source": "foo",
"@destination": "bar",
"...": "...",
"Body": {
"...": "..."
}
}
}
},
"...": "..."
}
How would i achieve this output in an efficient manner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tldr;
您是否看了看
您可以找到有关如何使用它的一些景象
Tldr;
Have you taken a look at logstash's xml filter
You can find some exemple on how to use it here