使用logstash-logback-编码器记录任意XML结构

发布于 2025-01-31 03:17:01 字数 1118 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朦胧时间 2025-02-07 03:17:01

tldr;

您是否看了看

您可以找到有关如何使用它的一些景象

Tldr;

Have you taken a look at logstash's xml filter

You can find some exemple on how to use it here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文