如何用flutterbit分割日志(键)字段?
我们使用 FluentBit 将 node.js 代码发送到 OpenSearch。我们遇到问题是因为 log 键包含嵌套值作为 message。我们需要拆分以下日志消息中提到的值 -
log- {"level":"info","message":"\"{\"method:\" GET , \"url:\" / , \"status:\" 404 , \"responseTime:\" 0.545 ms , \"responseContentLength:\" 39}\"\n","timestamp":"2022-04-01T12:48:37.091Z"}
我们需要将每个字段拆分为单独的 -
level: info 方法:获取 状态:404
We are sending node.js code to OpenSearch using FluentBit. We are having issues because log key contains nested value as message. We need to split the values mentioned in the below log message -
log- {"level":"info","message":"\"{\"method:\" GET , \"url:\" / , \"status:\" 404 , \"responseTime:\" 0.545 ms , \"responseContentLength:\" 39}\"\n","timestamp":"2022-04-01T12:48:37.091Z"}
We need to split each and every field as separate -
level: info
method: GET
status: 404
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
,解决方案分为两个部分:
我们遇到了类似的问题 看起来与 json 格式相关,特别是
message
字段(参见下面的第 2 点)1.在 Fluent-bit 配置文件中添加 Kubernetes 过滤器
现在,这会将 json 输出拆分到新字段中:
log
= "{original dict as string}"log_processed.level
= "info"log_processed.message
= 等等2.更正我们 API 中的 json 日志记录
json 中的
message
字段似乎输出为String
,而不是json
目的。即你有:
但你可能想要这个:
请注意,我在这里假设的数据类型只是为了演示问题。
一些相关的阅读/链接:
We had a similar problem and there was two parts to the solution:
Though your issue looks json format related, specifically for the
message
field (see point 2 below)1. Add Kubernetes filter in the Fluent-bit config file
Now this splits the json output in new fields:
log
= "{original dict as string}"log_processed.level
= "info"log_processed.message
= etc.2. Correct the json logging from our APIs
It looks like the
message
field in your json is outputting as aString
, not ajson
object.i.e. you have:
But you may want this instead:
Please note that I've assumed datatypes here to demonstrate the issue only.
Some relevant reading/links: