opensearch-project/OpenSearch

OpenSearchJsonLayout logs newlines in json

Open

#4673 aperta il 4 ott 2022

Vedi su GitHub
 (18 commenti) (1 reazione) (1 assegnatario)Java (1505 fork)batch import
Build Libraries & InterfacesPriority-Lowbugdiscussgood first issuelucene

Metriche repository

Star
 (8123 star)
Metriche merge PR
 (Merge medio 5g 9h) (266 PR mergiate in 30 g)

Descrizione

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)

Guida contributor