@@ -101,7 +101,9 @@ private ExtendedPatternLayout(
101
101
boolean disableAnsi ,
102
102
boolean noConsoleNoAnsi ,
103
103
String headerPattern ,
104
- String footerPattern ) {
104
+ String footerPattern ,
105
+ boolean initNewLine ,
106
+ boolean prettyPrinting ) {
105
107
super (
106
108
config ,
107
109
charset ,
@@ -113,6 +115,8 @@ private ExtendedPatternLayout(
113
115
.setDisableAnsi (disableAnsi )
114
116
.setNoConsoleNoAnsi (noConsoleNoAnsi )
115
117
.setPattern (headerPattern )
118
+ .setInitNewLine (initNewLine )
119
+ .setPrettyPrinting (prettyPrinting )
116
120
.build (),
117
121
newSerializerBuilder ()
118
122
.setConfiguration (config )
@@ -122,6 +126,8 @@ private ExtendedPatternLayout(
122
126
.setDisableAnsi (disableAnsi )
123
127
.setNoConsoleNoAnsi (noConsoleNoAnsi )
124
128
.setPattern (footerPattern )
129
+ .setInitNewLine (initNewLine )
130
+ .setPrettyPrinting (prettyPrinting )
125
131
.build ());
126
132
conversionPattern = eventPattern ;
127
133
this .patternSelector = patternSelector ;
@@ -135,6 +141,8 @@ private ExtendedPatternLayout(
135
141
.setNoConsoleNoAnsi (noConsoleNoAnsi )
136
142
.setPattern (eventPattern )
137
143
.setDefaultPattern ("%m%n" )
144
+ .setInitNewLine (initNewLine )
145
+ .setPrettyPrinting (prettyPrinting )
138
146
.build ();
139
147
}
140
148
@@ -339,6 +347,8 @@ public static ExtendedPatternLayout createLayout(
339
347
.withNoConsoleNoAnsi (noConsoleNoAnsi )
340
348
.withHeader (headerPattern )
341
349
.withFooter (footerPattern )
350
+ .withInitNewLine (false )
351
+ .withPrettyPrinting (false )
342
352
.build ();
343
353
}
344
354
@@ -404,12 +414,8 @@ public static final class Builder
404
414
@ PluginBuilderAttribute private boolean noConsoleNoAnsi ;
405
415
@ PluginBuilderAttribute private String header ;
406
416
@ PluginBuilderAttribute private String footer ;
407
-
408
- @ PluginBuilderAttribute ("initNewLine" )
409
- private static boolean initNewLine ;
410
-
411
- @ PluginBuilderAttribute ("prettyPrinting" )
412
- private static boolean prettyPrinting ;
417
+ @ PluginBuilderAttribute private boolean initNewLine ;
418
+ @ PluginBuilderAttribute private boolean prettyPrinting ;
413
419
414
420
private Builder () {
415
421
super ();
@@ -541,6 +547,28 @@ public ExtendedPatternLayout.Builder withFooter(String footer) {
541
547
return this ;
542
548
}
543
549
550
+ /**
551
+ * Sets whether to start byte array output on a new line.
552
+ *
553
+ * @param initNewLine Whether to initialize byte array output on a new line
554
+ * @return This builder instance
555
+ */
556
+ public ExtendedPatternLayout .Builder withInitNewLine (boolean initNewLine ) {
557
+ this .initNewLine = initNewLine ;
558
+ return this ;
559
+ }
560
+
561
+ /**
562
+ * Sets whether to format byte arrays with spaces between bytes for readability.
563
+ *
564
+ * @param prettyPrinting Whether to pretty print byte arrays
565
+ * @return This builder instance
566
+ */
567
+ public ExtendedPatternLayout .Builder withPrettyPrinting (boolean prettyPrinting ) {
568
+ this .prettyPrinting = prettyPrinting ;
569
+ return this ;
570
+ }
571
+
544
572
/**
545
573
* Builds a new ExtendedPatternLayout instance with the configured settings.
546
574
*
@@ -565,7 +593,9 @@ public ExtendedPatternLayout build() {
565
593
disableAnsi ,
566
594
noConsoleNoAnsi ,
567
595
header ,
568
- footer );
596
+ footer ,
597
+ initNewLine ,
598
+ prettyPrinting );
569
599
}
570
600
}
571
601
@@ -655,6 +685,8 @@ public SerializerBuilder() {
655
685
private boolean alwaysWriteExceptions ;
656
686
private boolean disableAnsi ;
657
687
private boolean noConsoleNoAnsi ;
688
+ private boolean initNewLine ;
689
+ private boolean prettyPrinting ;
658
690
659
691
/**
660
692
* Builds a serializer for formatting log events according to the configured settings.
@@ -685,7 +717,7 @@ public AbstractStringLayout.Serializer build() {
685
717
noConsoleNoAnsi );
686
718
PatternFormatter [] formatters = list .toArray (new PatternFormatter [0 ]);
687
719
return new ExtendedPatternLayout .ExtendedPatternLayoutSerializer (
688
- formatters , replace );
720
+ formatters , replace , initNewLine , prettyPrinting );
689
721
} catch (RuntimeException var4 ) {
690
722
throw new IllegalArgumentException (
691
723
"Cannot parse pattern '" + pattern + "'" , var4 );
@@ -786,18 +818,47 @@ public ExtendedPatternLayout.SerializerBuilder setNoConsoleNoAnsi(boolean noCons
786
818
this .noConsoleNoAnsi = noConsoleNoAnsi ;
787
819
return this ;
788
820
}
821
+
822
+ /**
823
+ * Sets whether to start byte array output on a new line.
824
+ *
825
+ * @param initNewLine Whether to initialize byte array output on a new line
826
+ * @return This builder instance
827
+ */
828
+ public ExtendedPatternLayout .SerializerBuilder setInitNewLine (boolean initNewLine ) {
829
+ this .initNewLine = initNewLine ;
830
+ return this ;
831
+ }
832
+
833
+ /**
834
+ * Sets whether to format byte arrays with spaces between bytes for readability.
835
+ *
836
+ * @param prettyPrinting Whether to pretty print byte arrays
837
+ * @return This builder instance
838
+ */
839
+ public ExtendedPatternLayout .SerializerBuilder setPrettyPrinting (boolean prettyPrinting ) {
840
+ this .prettyPrinting = prettyPrinting ;
841
+ return this ;
842
+ }
789
843
}
790
844
791
845
private static final class ExtendedPatternLayoutSerializer
792
846
implements AbstractStringLayout .Serializer , LocationAware {
793
847
private final PatternFormatter [] formatters ;
794
848
private final RegexReplacement replace ;
849
+ private final boolean initNewLine ;
850
+ private final boolean prettyPrinting ;
795
851
796
852
private ExtendedPatternLayoutSerializer (
797
- PatternFormatter [] formatters , RegexReplacement replace ) {
853
+ PatternFormatter [] formatters ,
854
+ RegexReplacement replace ,
855
+ boolean initNewLine ,
856
+ boolean prettyPrinting ) {
798
857
super ();
799
858
this .formatters = formatters ;
800
859
this .replace = replace ;
860
+ this .initNewLine = initNewLine ;
861
+ this .prettyPrinting = prettyPrinting ;
801
862
}
802
863
803
864
@ Override
@@ -831,11 +892,13 @@ public String toSerializable(LogEvent event) {
831
892
* </ul>
832
893
* </ol>
833
894
*
834
- * <p>The byte array formatting is controlled by two static configuration options:
895
+ * <p>The byte array formatting is controlled by two configuration options:
835
896
*
836
897
* <ul>
837
- * <li>{@link Builder#prettyPrinting} - Whether to format with spaces between bytes
838
- * <li>{@link Builder#initNewLine} - Whether to start byte arrays on a new line
898
+ * <li>{@link ExtendedPatternLayoutSerializer#prettyPrinting} - Whether to format with
899
+ * spaces between bytes
900
+ * <li>{@link ExtendedPatternLayoutSerializer#initNewLine} - Whether to start byte arrays
901
+ * on a new line
839
902
* </ul>
840
903
*
841
904
* @param event The LogEvent to serialize
@@ -870,9 +933,7 @@ public StringBuilder toSerializable(LogEvent event, StringBuilder builder) {
870
933
builder .indexOf (Arrays .toString ((byte []) param ))
871
934
+ Arrays .toString ((byte []) param ).length (),
872
935
DataConverter .bytesToHexString (
873
- (byte []) param ,
874
- Builder .prettyPrinting ,
875
- Builder .initNewLine ));
936
+ (byte []) param , prettyPrinting , initNewLine ));
876
937
}
877
938
}
878
939
}
0 commit comments