【问题标题】:Send JSON from log4js to logstash and fields将 JSON 从 log4js 发送到 logstash 和字段
【发布时间】:2016-11-03 17:34:48
【问题描述】:

我正在使用log4js 记录我的应用程序,我想将日志发送到logstash。

这是 log4js from here 的默认附加程序:

 "appenders": [
    {
      "type": "console"
    },
    {
      "host": "127.0.0.1",
      "port": 5000,
      "type": "logstashUDP"
    }
  ]

这里是logstash配置文件:

input {
  udp {
    port => 5000
    type => "json"
  }
}

filter {
  date {
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
  }
}

output {
  stdout {}
}

发送日志工作正常,但我正在发送 JSON 日志,在 logstash 中,我看到 json 的每个字符都有一个字段。

2016-07-01T10:29:36.161Z 127.0.0.1 {"@version":"1","@timestamp":"2016-07-01T10:29:36.160Z","message":"我的 消息...","字段":{"0":"{","1":"\n","2":" ","3":" ","4":"\"" , ...

我是 logstash 的新手,但我喜欢将所有字段分组在一个大字符串中。我该怎么做?

【问题讨论】:

  • 你可能需要在你的 udp 中使用 codec => "json" 来告诉它传入的日志是 json 日志。默认是普通的
  • @pandaadb 好的,谢谢,如果您可以将其添加为答案,我会检查它是否已接受,否则我将删除问题

标签: json logging logstash log4js-node


【解决方案1】:

为了让您的输入知道它是 json,您需要为其添加编解码器:

input {
  udp {
    port => 5000
    type => "json"
    codec => "json"
  }
}

问候,

阿图尔

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多