简体   繁体   English

在 FluentD 中将字符串解析为 JSON

[英]Parse string to JSON in FluentD

I have this log string:我有这个日志字符串:

2019-03-18 15:56:57.5522 | HandFarm | ResolveDispatcher | start resolving msg: 8

Please tell me how I can parse this string to JSON format in fluentd.conf?请告诉我如何在 fluentd.conf 中将此字符串解析为 JSON 格式? I need the following format:我需要以下格式:

{
  "timestamp"  : "2019-03-18 15:56:57.5522",
  "system"  : "HandFarm",
  "module": "ResolveDispatcher",
  "message": "start resolving msg: 8",
}

I tried to use standard formatters, nothing came of it..我尝试使用标准格式化程序,但没有任何结果..

You could use regexp parser and format events to JSON.您可以使用正则表达式解析器并将事件格式化为 JSON。 Here is an example of mine where I am reading the input from log file tail(with same input as yours) and output to stdout.这是我的一个示例,我从日志文件尾部读取输入(与您的输入相同)并输出到标准输出。 Let me know.让我知道。

<source>
  @type tail
  path /tailsource/t.log
  pos_file /tailpos/t.log.pos
  read_from_head true
  tag temp
  <parse>
    @type regexp
    expression /^(?<timestamp>.*?)\s\| (?<system>.*?)\s\| (?<module>.*?)\s\| (?<message>.*)$/
  </parse>
</source>

<match>
  @type stdout
</match>

Here is sample output -这是示例输出 -

{"timestamp":"2019-03-18 15:56:57.5522","system":"HandFarm","module":"ResolveDispatcher","message":"start resolving msg: 8"} {"timestamp":"2019-03-18 15:56:57.5522","system":"HandFarm","module":"ResolveDispatcher","message":"开始解析消息:8"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM