Is there a way to set JSON object to elasticsearch index as key-value pairs via AsyncLogger using log4j2-elasticsearch-hc appender

huangapple go评论80阅读模式
英文:

Is there a way to set JSON object to elasticsearch index as key-value pairs via AsyncLogger using log4j2-elasticsearch-hc appender

问题

我正在使用log4j2-elasticsearch-hc appender(asyncLogger)将日志直接写入ElasticSearch。我的日志基本上是Log POJO(即JSON)。然而,当我使用Logger.info(logPojoInstance)时,整个实例会被字符串化为一个名为"message"的属性,而不是键值对。请查看下面的屏幕截图中的ElasticSearch输出:

如何才能以键值对的形式显示LogDTO,而不是以字符串化/序列化的JSON形式显示在message旁边...在这种情况下,我希望能够查询这些日志,但目前不可能。

我尝试了VirtualProperty的方法,但由于我正在使用AsyncLogger,似乎无法设置值。

如果有任何线索,请告诉我!

同时,附上log4j2.xml供参考:

英文:

I am using the Using log4j2-elasticsearch-hc appender (asyncLogger) to directly write my logs to ElasticSearch. My log is basically Log POJO (i.e. JSON). However; when I say; Logger.info(logPojoInstance); the entire instance gets stringified against a property named "message" as opposed to being key-value pairs. Please look at the ElasticSearch output in the screenshot below :Is there a way to set JSON object to elasticsearch index as key-value pairs via AsyncLogger using log4j2-elasticsearch-hc appender

What can be done so that the LogDTO is displayed in key-value as opposed to a stringified / serialized json adjacent to message....I want to be able to query these logs which wont be possible in this scenario.

I tried the VirtualProperty approach but as I am using AsyncLogger the value does not seem to set.

<VirtualProperty name="ctxVariable" value="$${ctx:myFavouriteVariable:-notSupportedWithAsyncLogger}" dynamic="true" />

Any leads please let me know !

Also pasting the log4j2.xml for reference :

答案1

得分: 1

你可以使用官方的JSON模板布局log4j2-elasticsearch-hc结合使用。JTL是最丰富和可定制的基于JSON的布局,可以呈现非String类型的消息。有关详细信息,请参阅消息事件模板解析器文档

英文:

You can use the official JSON Template Layout in combination with log4j2-elasticsearch-hc. JTL is the most feature-rich and customizable JSON-based layout in the wild and can render non-String messages. See the message event template resolver docs for details.

答案2

得分: 0

目前似乎不可能:https://github.com/rfoltyns/log4j2-elasticsearch/issues/91

英文:

Seems like not possible currently : https://github.com/rfoltyns/log4j2-elasticsearch/issues/91

huangapple
  • 本文由 发表于 2023年8月8日 23:02:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76860819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定