opensearch-project/OpenSearch

OpenSearchJsonLayout logs newlines in json

Open

#4,673 创建于 2022年10月4日

在 GitHub 查看
 (18 评论) (1 反应) (1 负责人)Java (1,505 fork)batch import
Build Libraries & InterfacesPriority-Lowbugdiscussgood first issuelucene

仓库指标

Star
 (8,123 star)
PR 合并指标
 (平均合并 5天 9小时) (30 天内合并 266 个 PR)

描述

Describe the bug Using the OpenSearchJsonLayout for logging out of a docker container adds newlines in the generated json-string when a stack-trace is appended. This makes it unnecessarily hard to process the logs by a line based log-agent.

To Reproduce Steps to reproduce the behavior: Use the following log4j2 config:


appender.console.type = Console
appender.console.name = console
appender.console.layout.type = OpenSearchJsonLayout
appender.console.layout.type_name = server

rootLogger.level = info
rootLogger.appenderRef.console.ref = console

which generates logs like this:

{ ... "cluster.uuid": "KK8EloHiQGCbVCUO3RPkmg", "node.id": "HTVcLMDtRLSgVqq2w5l0UA" ,
"stacktrace": ["java.lang.NullPointerException: Cannot invoke \"String.length()\" because \"other\" is null",
"at org.apache.lucene.search.spell.LevenshteinDistance.getDistance(LevenshteinDistance.java:62)"
...
"at java.lang.Thread.run(Thread.java:833) [?:?]"] }

Expected behavior Not adding unnecessary newlines.

The newlines are injected here: https://github.com/opensearch-project/OpenSearch/blob/10bff0c9f5b9ca78b3dc50f5c704dabf41b9d535/server/src/main/java/org/opensearch/common/logging/JsonThrowablePatternConverter.java

Is there any reason for those or can they get removed?

Host/Environment (please complete the following information):

  • OS: Ubuntu 22.04 (docker)

贡献者指南