OpenSearchJsonLayout logs newlines in json
#4.673 aberto em 4 de out. de 2022
Métricas do repositório
- Stars
- (8.123 stars)
- Métricas de merge de PR
- (Mesclagem média 5d 9h) (266 fundiu PRs em 30d)
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)