Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "%property{key}" return an empty string instead of "null" when used in PatternJsonProvider #772

Merged
merged 4 commits into from
Mar 12, 2022

Conversation

brenuart
Copy link
Collaborator

@brenuart brenuart commented Mar 9, 2022

The behaviour of the %property{key} conversion specifier is slightly modified to return an empty string when the property is not defined instead of null as it normally does. Assuming the "foo" property does not exist, the following configuration:

<pattern>
   { "foo": "%property{foo}" }
</pattern>

... will produce something like this:

{ "foo": "" }

... instead of:

{ "foo": "null" }

The foo property will now be successfully omitted when omitEmptyField is true.

The property conversion specifier now also accepts an optional default value to use when the property does not exist. Assuming the property "foo" is not defined, %property{foo:-bar} will return bar instead of an empty string.

People wanting to revert to the original behaviour of returning "null" instead of an empty string can explicitly defined a default value of "null".

This should close #765

@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #772 (81f8910) into main (72c7fa1) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #772      +/-   ##
============================================
+ Coverage     70.55%   70.70%   +0.14%     
- Complexity     1228     1237       +9     
============================================
  Files           162      163       +1     
  Lines          4728     4752      +24     
  Branches        481      486       +5     
============================================
+ Hits           3336     3360      +24     
  Misses         1146     1146              
  Partials        246      246              
Impacted Files Coverage Δ
...logstash/logback/pattern/PatternLayoutAdapter.java 83.67% <ø> (ø)
...ash/logback/pattern/EnhancedPropertyConverter.java 100.00% <100.00%> (ø)
...logback/pattern/LoggingEventJsonPatternParser.java 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72c7fa1...81f8910. Read the comment docs.

@brenuart brenuart requested a review from philsttr March 9, 2022 23:01
Copy link
Collaborator

@philsttr philsttr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a couple super minor things.

@brenuart brenuart merged commit 51a3924 into main Mar 12, 2022
@brenuart brenuart deleted the gs765-omitEmptyField-property branch March 12, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PatternJsonProvider: omitEmptyFields doesn't work with %property(ENV_VAR)
2 participants