34
34
35
35
import org .apache .logging .log4j .core .Layout ;
36
36
import org .apache .logging .log4j .core .LogEvent ;
37
+ import org .apache .logging .log4j .core .config .Configuration ;
37
38
import org .apache .logging .log4j .core .config .Node ;
38
39
import org .apache .logging .log4j .core .config .plugins .Plugin ;
39
40
import org .apache .logging .log4j .core .config .plugins .PluginAttribute ;
40
41
import org .apache .logging .log4j .core .config .plugins .PluginBuilderFactory ;
42
+ import org .apache .logging .log4j .core .config .plugins .PluginConfiguration ;
41
43
import org .apache .logging .log4j .core .config .plugins .PluginFactory ;
42
44
import org .apache .logging .log4j .core .layout .AbstractStringLayout ;
43
45
import org .apache .logging .log4j .core .layout .ByteBufferDestination ;
@@ -94,11 +96,18 @@ public class OpenSearchJsonLayout extends AbstractStringLayout {
94
96
95
97
private final PatternLayout patternLayout ;
96
98
97
- protected OpenSearchJsonLayout (String typeName , Charset charset , String [] opensearchMessageFields , int maxMessageLength ) {
99
+ protected OpenSearchJsonLayout (
100
+ String typeName ,
101
+ Charset charset ,
102
+ String [] opensearchMessageFields ,
103
+ int maxMessageLength ,
104
+ Configuration configuration
105
+ ) {
98
106
super (charset );
99
107
this .patternLayout = PatternLayout .newBuilder ()
100
108
.withPattern (pattern (typeName , opensearchMessageFields , maxMessageLength ))
101
109
.withAlwaysWriteExceptions (false )
110
+ .withConfiguration (configuration )
102
111
.build ();
103
112
}
104
113
@@ -173,8 +182,14 @@ private String inQuotes(String s) {
173
182
}
174
183
175
184
@ PluginFactory
176
- public static OpenSearchJsonLayout createLayout (String type , Charset charset , String [] opensearchmessagefields , int maxMessageLength ) {
177
- return new OpenSearchJsonLayout (type , charset , opensearchmessagefields , maxMessageLength );
185
+ public static OpenSearchJsonLayout createLayout (
186
+ String type ,
187
+ Charset charset ,
188
+ String [] opensearchmessagefields ,
189
+ int maxMessageLength ,
190
+ Configuration configuration
191
+ ) {
192
+ return new OpenSearchJsonLayout (type , charset , opensearchmessagefields , maxMessageLength , configuration );
178
193
}
179
194
180
195
PatternLayout getPatternLayout () {
@@ -202,6 +217,9 @@ public static class Builder<B extends OpenSearchJsonLayout.Builder<B>> extends A
202
217
@ PluginAttribute (value = "maxmessagelength" , defaultInt = 10000 )
203
218
private int maxMessageLength ;
204
219
220
+ @ PluginConfiguration
221
+ private Configuration configuration ;
222
+
205
223
public Builder () {
206
224
setCharset (StandardCharsets .UTF_8 );
207
225
setMaxMessageLength (10000 );
@@ -210,7 +228,7 @@ public Builder() {
210
228
@ Override
211
229
public OpenSearchJsonLayout build () {
212
230
String [] split = Strings .isNullOrEmpty (opensearchMessageFields ) ? new String [] {} : opensearchMessageFields .split ("," );
213
- return OpenSearchJsonLayout .createLayout (type , charset , split , maxMessageLength );
231
+ return OpenSearchJsonLayout .createLayout (type , charset , split , maxMessageLength , configuration );
214
232
}
215
233
216
234
public Charset getCharset () {
@@ -248,6 +266,15 @@ public B setMaxMessageLength(final int maxMessageLength) {
248
266
this .maxMessageLength = maxMessageLength ;
249
267
return asBuilder ();
250
268
}
269
+
270
+ public Configuration getConfiguration () {
271
+ return configuration ;
272
+ }
273
+
274
+ public B setConfiguration (final Configuration configuration ) {
275
+ this .configuration = configuration ;
276
+ return asBuilder ();
277
+ }
251
278
}
252
279
253
280
@ PluginBuilderFactory
0 commit comments