首页 > 解决方案 > JSONLayout endOfLine 属性未按预期工作

问题描述

我在我的项目的 log4j2.xml 文件中使用此配置以在一行中获取 JSON 格式的日志:

<JsonLayout compact="true" eventEOL="true" endOfLine="\n" properties="true"/>

\r\n使用时默认情况下,每一行都由 分隔eventEOL="true",但是我不希望\r使用.endOfLine\n

我希望日志以新行发出,而是\n打印为字符串。

预期的:

{"message":"I want this"}
{"message":"new log in new line"}

当前行为:

{"message":"I want this"}\n{"message":"new log in new line"}

注意:我不想要的原因\r是因为 Splunk 无法解析\r事件文本中带有 (#015) 的 JSON 日志。

相关文档:https ://logging.apache.org/log4j/2.x/manual/layouts.html#JSONLayout

任何建议表示赞赏。

标签: javajsonlogginglog4j2splunk

解决方案


推荐阅读