File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
cf-java-logging-support-log4j2/src
main/java/com/sap/hcp/cf/log4j2/layout
test/java/com/sap/hcp/cf/log4j2/layout Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ public LayoutPatternBuilder addContextProperties(List<String> exclusions) {
5656 }
5757
5858 public LayoutPatternBuilder addCustomFields (List <String > mdcKeyNames ) {
59+ if (mdcKeyNames == null || mdcKeyNames .isEmpty ()) {
60+ return this ;
61+ }
5962 sb .append ("\" " ).append (Fields .CUSTOM_FIELDS ).append ("\" :" );
6063 sb .append ("{%" ).append (CustomFieldsConverter .WORD );
6164 appendParameters (mdcKeyNames );
Original file line number Diff line number Diff line change 22
33import static java .util .Arrays .asList ;
44import static java .util .Collections .emptyList ;
5+ import static org .hamcrest .MatcherAssert .assertThat ;
56import static org .hamcrest .Matchers .is ;
67import static org .hamcrest .Matchers .isEmptyString ;
7- import static org .junit .Assert .assertThat ;
88
99import java .util .Arrays ;
10+ import java .util .Collections ;
1011
1112import org .hamcrest .FeatureMatcher ;
1213import org .hamcrest .Matcher ;
@@ -54,6 +55,20 @@ public void customFields() throws Exception {
5455 assertThat (pattern , specificPart (is (",\" #cf\" :{%cf{this key}{that key}}" )));
5556 }
5657
58+ @ Test
59+ public void emptyCustomFields () throws Exception {
60+ String pattern = new LayoutPatternBuilder ().addCustomFields (Collections .emptyList ()).build ();
61+
62+ assertThat (pattern , specificPart (is ("" )));
63+ }
64+
65+ @ Test
66+ public void nullCustomFields () throws Exception {
67+ String pattern = new LayoutPatternBuilder ().addCustomFields (null ).build ();
68+
69+ assertThat (pattern , specificPart (is ("" )));
70+ }
71+
5772 @ Test
5873 public void stacktrace () throws Exception {
5974 String pattern = new LayoutPatternBuilder ().addStacktraces ().build ();
You can’t perform that action at this time.
0 commit comments