opensearch-project/OpenSearch

OpenSearchJsonLayout logs newlines in json

Open

#4 673 ouverte le 4 oct. 2022

Voir sur GitHub
 (18 commentaires) (1 réaction) (1 assigné)Java (1 505 forks)batch import
Build Libraries & InterfacesPriority-Lowbugdiscussgood first issuelucene

Métriques du dépôt

Stars
 (8 123 stars)
Métriques de merge PR
 (Merge moyen 5j 9h) (266 PRs mergées en 30 j)

Description

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)

Guide contributeur