You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Excerpt from original post by ziomill February 16, 2022
I'm trying to use the "omitEmptyFields" to print/omit an ENV variable, without success. If the ENV_VAR 'CONTAINER_NAMESPACE' is not populated, the logger prints "null" as the field's value rather than omit the field.
...
This is my configuration:
The Pattern json provider is using a standard Logback PatternLayout under the hood to resolve placeholders and converters in the pattern string. The resulting string is then converted into JSON and added to the final result. The "omitEmptyFields" property works by telling Jackson to omit fields whose value is considered empty.
When a property does not exist, the %property{} converter returns null and this value is unfortunately added "asis" to the internal StringBuilder. In this example, the original pattern is converted into the string {"container-namespace":"null"} before it is transformed into a valid JSON structure by Jackson. Since the property is not null but is assigned a String value, it is not filtered out by Jackson's "empty field" filtering mechanism.
The text was updated successfully, but these errors were encountered:
brenuart
changed the title
PatternJsonProvider - omitEmptyFields doesn't work with %property(ENV_VAR)
PatternJsonProvider: omitEmptyFields doesn't work with %property(ENV_VAR)
Mar 9, 2022
Discussed in #760
Excerpt from original post by ziomill February 16, 2022
I'm trying to use the "omitEmptyFields" to print/omit an ENV variable, without success. If the ENV_VAR 'CONTAINER_NAMESPACE' is not populated, the logger prints "null" as the field's value rather than omit the field.
...
This is my configuration:
And this is the printed log record:
Root Cause
The Pattern json provider is using a standard Logback PatternLayout under the hood to resolve placeholders and converters in the pattern string. The resulting string is then converted into JSON and added to the final result. The "omitEmptyFields" property works by telling Jackson to omit fields whose value is considered empty.
When a property does not exist, the
%property{}
converter returnsnull
and this value is unfortunately added "asis" to the internal StringBuilder. In this example, the original pattern is converted into the string{"container-namespace":"null"}
before it is transformed into a valid JSON structure by Jackson. Since the property is not null but is assigned a String value, it is not filtered out by Jackson's "empty field" filtering mechanism.The text was updated successfully, but these errors were encountered: