forked from logfellow/logstash-logback-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShortenedThrowableConverter.java
660 lines (588 loc) · 26 KB
/
ShortenedThrowableConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.logstash.logback.stacktrace;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import ch.qos.logback.access.PatternLayout;
import ch.qos.logback.classic.pattern.Abbreviator;
import ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator;
import ch.qos.logback.classic.pattern.ThrowableHandlingConverter;
import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.StackTraceElementProxy;
import ch.qos.logback.classic.spi.ThrowableProxy;
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.boolex.EvaluationException;
import ch.qos.logback.core.boolex.EventEvaluator;
import ch.qos.logback.core.status.ErrorStatus;
import net.logstash.logback.CachingAbbreviator;
import net.logstash.logback.NullAbbreviator;
/**
* A {@link ThrowableHandlingConverter} (similar to logback's {@link ThrowableProxyConverter})
* that formats stacktraces by doing the following:
*
* <ul>
* <li>Limits the number of stackTraceElements per throwable
* (applies to each individual throwable. e.g. caused-bys and suppressed).
* See {@link #maxDepthPerThrowable}.</li>
* <li>Limits the total length in characters of the trace.
* See {@link #maxLength}.</li>
* <li>Abbreviates class names based on the {@link #shortenedClassNameLength}.
* See {@link #shortenedClassNameLength}.</li>
* <li>Filters out consecutive unwanted stackTraceElements based on regular expressions.
* See {@link #excludes}.</li>
* <li>Uses evaluators to determine if the stacktrace should be logged.
* See {@link #evaluators}.</li>
* <li>Outputs in either 'normal' order (root-cause-last), or root-cause-first.
* See {@link #rootCauseFirst}.</li>
* </ul>
*
* <p>
* To use this with a {@link PatternLayout}, you must configure <tt>conversionRule</tt>
* as described <a href="http://logback.qos.ch/manual/layouts.html#customConversionSpecifier">here</a>.
* Options can be specified in the pattern in the following order:
* <ol>
* <li>maxDepthPerThrowable = "full" or "short" or an integer value</li>
* <li>shortenedClassNameLength = "full" or "short" or an integer value</li>
* <li>maxLength = "full" or "short" or an integer value</li>
* </ol>
* If any other remaining options are "rootFirst",
* then the converter awill be configured as root-cause-first.
* If any other remaining options equal to an evaluator name,
* then the evaluator will be used to determine if the stacktrace should be printed.
* Other options will be interpreted as exclusion regexes.
* <p>
* For example,
* <pre>
* {@code
* <conversionRule conversionWord="stack"
* converterClass="net.logstash.logback.stacktrace.ShortenedThrowableConverter" />
*
* <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
* <encoder>
* <pattern>[%thread] - %msg%n%stack{5,1024,10,rootFirst,regex1,regex2,evaluatorName}</pattern>
* </encoder>
* </appender>
* }
* </pre>
*
*
*
*/
public class ShortenedThrowableConverter extends ThrowableHandlingConverter {
public static final int FULL_MAX_DEPTH_PER_THROWABLE = Integer.MAX_VALUE;
public static final int SHORT_MAX_DEPTH_PER_THROWABLE = 3;
public static final int DEFAULT_MAX_DEPTH_PER_THROWABLE = FULL_MAX_DEPTH_PER_THROWABLE;
public static final int FULL_MAX_LENGTH = Integer.MAX_VALUE;
public static final int SHORT_MAX_LENGTH = 1024;
public static final int DEFAULT_MAX_LENGTH = FULL_MAX_LENGTH;
public static final int FULL_CLASS_NAME_LENGTH = Integer.MAX_VALUE;
public static final int SHORT_CLASS_NAME_LENGTH = 10;
public static final int DEFAULT_CLASS_NAME_LENGTH = FULL_CLASS_NAME_LENGTH;
private static final String ELLIPSIS = "...";
private static final int BUFFER_INITIAL_CAPACITY = 4096;
private static final String OPTION_VALUE_FULL = "full";
private static final String OPTION_VALUE_SHORT = "short";
private static final String OPTION_VALUE_ROOT_FIRST = "rootFirst";
private static final String OPTION_VALUE_INLINE_HASH = "inlineHash";
private static final int OPTION_INDEX_MAX_DEPTH = 0;
private static final int OPTION_INDEX_SHORTENED_CLASS_NAME = 1;
private static final int OPTION_INDEX_MAX_LENGTH = 2;
private AtomicInteger errorCount = new AtomicInteger();
/**
* Maximum number of stackTraceElements printed per throwable.
*/
private int maxDepthPerThrowable = DEFAULT_MAX_DEPTH_PER_THROWABLE;
/**
* Maximum number of characters in the entire stacktrace.
*/
private int maxLength = DEFAULT_MAX_LENGTH;
/**
* Will try to shorten class name lengths to less than this value
*/
private int shortenedClassNameLength = DEFAULT_CLASS_NAME_LENGTH;
/**
* Abbreviator that will shorten the classnames if {@link #shortenedClassNameLength}
* is set less than {@link #FULL_CLASS_NAME_LENGTH}
*/
private Abbreviator abbreviator = NullAbbreviator.INSTANCE;
/**
* Patterns used to determine which stacktrace elements to exclude.
*
* The strings being matched against are in the form "fullyQualifiedClassName.methodName"
* (e.g. "java.lang.Object.toString").
*
* Note that these elements will only be excluded if and only if
* more than one consecutive line matches an exclusion pattern.
*/
private List<Pattern> excludes = new ArrayList<Pattern>(5);
/**
* True to print the root cause first. False to print exceptions normally (root cause last).
*/
private boolean rootCauseFirst;
/**
* True to compute and inline stack hashes.
*/
private boolean inlineHash;
private StackElementFilter stackElementFilter;
private StackHasher stackHasher;
/**
* Evaluators that determine if the stacktrace should be logged.
*/
private List<EventEvaluator<ILoggingEvent>> evaluators = new ArrayList<EventEvaluator<ILoggingEvent>>(1);
@Override
public void start() {
parseOptions();
// instantiate stack element filter
if(excludes == null || excludes.isEmpty()) {
if(inlineHash) {
// filter out elements with no source info
addInfo("[inlineHash] is active with no exclusion pattern: use non null source info filter to exclude generated classnames (see doc)");
stackElementFilter = StackElementFilter.withSourceInfo();
} else {
// use any filter
stackElementFilter = StackElementFilter.any();
}
} else {
// use patterns filter
stackElementFilter = StackElementFilter.byPattern(excludes);
}
// instantiate stack hasher if "inline hash" is active
if(inlineHash) {
stackHasher = new StackHasher(stackElementFilter);
}
super.start();
}
private void parseOptions() {
List<String> optionList = getOptionList();
if (optionList == null) {
return;
}
final int optionListSize = optionList.size();
for (int i = 0; i < optionListSize; i++) {
String option = optionList.get(i);
switch (i) {
case OPTION_INDEX_MAX_DEPTH:
setMaxDepthPerThrowable(parseIntegerOptionValue(option, FULL_MAX_DEPTH_PER_THROWABLE, SHORT_MAX_DEPTH_PER_THROWABLE, DEFAULT_MAX_DEPTH_PER_THROWABLE));
break;
case OPTION_INDEX_SHORTENED_CLASS_NAME:
setShortenedClassNameLength(parseIntegerOptionValue(option, FULL_CLASS_NAME_LENGTH, SHORT_CLASS_NAME_LENGTH, DEFAULT_CLASS_NAME_LENGTH));
break;
case OPTION_INDEX_MAX_LENGTH:
setMaxLength(parseIntegerOptionValue(option, FULL_MAX_LENGTH, SHORT_MAX_LENGTH, DEFAULT_MAX_LENGTH));
break;
default:
/*
* Remaining options are either
* - "rootFirst" - indicating that stacks should be printed root-cause first
* - "inlineHash" - indicating that hexadecimal error hashes should be computed and inlined
* - evaluator name - name of evaluators that will determine if the stacktrace is ignored
* - exclusion pattern - pattern for stack trace elements to exclude
*/
if (OPTION_VALUE_ROOT_FIRST.equals(option)) {
setRootCauseFirst(true);
} else if(OPTION_VALUE_INLINE_HASH.equals(option)) {
setInlineHash(true);
} else {
@SuppressWarnings("rawtypes")
Map evaluatorMap = (Map) getContext().getObject(CoreConstants.EVALUATOR_MAP);
@SuppressWarnings("unchecked")
EventEvaluator<ILoggingEvent> evaluator = (evaluatorMap != null)
? (EventEvaluator<ILoggingEvent>) evaluatorMap.get(option)
: null;
if (evaluator != null) {
addEvaluator(evaluator);
} else {
addExclude(option);
}
}
break;
}
}
}
private int parseIntegerOptionValue(String option, int valueIfFull, int valueIfShort, int valueIfNonParsable) {
if (OPTION_VALUE_FULL.equals(option)) {
return valueIfFull;
} else if (OPTION_VALUE_SHORT.equals(option)) {
return valueIfShort;
} else {
try {
return Integer.parseInt(option);
} catch (NumberFormatException nfe) {
addError("Could not parse [" + option + "] as an integer");
return valueIfNonParsable;
}
}
}
@Override
public String convert(ILoggingEvent event) {
IThrowableProxy throwableProxy = event.getThrowableProxy();
if (throwableProxy == null || isExcludedByEvaluator(event)) {
return CoreConstants.EMPTY_STRING;
}
// compute stack trace hashes
Deque<String> stackHashes = null;
if(inlineHash && (throwableProxy instanceof ThrowableProxy)) {
stackHashes = stackHasher.hexHashes(((ThrowableProxy) throwableProxy).getThrowable());
}
/*
* The extra 100 gives a little more buffer room since we actually
* go over the maxLength before detecting it and truncating.
*/
StringBuilder builder = new StringBuilder(Math.min(BUFFER_INITIAL_CAPACITY, this.maxLength + 100 > 0 ? this.maxLength + 100 : this.maxLength));
if (rootCauseFirst) {
appendRootCauseFirst(builder, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, throwableProxy, stackHashes);
} else {
appendRootCauseLast(builder, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, throwableProxy, stackHashes);
}
if (builder.length() > maxLength) {
builder.setLength(maxLength - ELLIPSIS.length());
builder.append(ELLIPSIS);
}
return builder.toString();
}
/**
* Return true if any evaluator returns true, indicating that
* the stack trace should not be logged.
*/
private boolean isExcludedByEvaluator(ILoggingEvent event) {
for (int i = 0; i < evaluators.size(); i++) {
EventEvaluator<ILoggingEvent> evaluator = evaluators.get(i);
try {
if (evaluator.evaluate(event)) {
return true;
}
} catch (EvaluationException eex) {
int errors = errorCount.incrementAndGet();
if (errors < CoreConstants.MAX_ERROR_COUNT) {
addError(String.format("Exception thrown for evaluator named [%s]", evaluator.getName()), eex);
} else if (errors == CoreConstants.MAX_ERROR_COUNT) {
ErrorStatus errorStatus = new ErrorStatus(
String.format("Exception thrown for evaluator named [%s]", evaluator.getName()), this, eex);
errorStatus.add(new ErrorStatus(
"This was the last warning about this evaluator's errors."
+ "We don't want the StatusManager to get flooded.",
this));
addStatus(errorStatus);
}
}
}
return false;
}
/**
* Appends a throwable and recursively appends its causedby/suppressed throwables
* in "normal" order (Root cause last).
*/
private void appendRootCauseLast(
StringBuilder builder,
String prefix,
int indent,
IThrowableProxy throwableProxy,
Deque<String> stackHashes) {
if (throwableProxy == null || builder.length() > maxLength) {
return;
}
String hash = stackHashes == null || stackHashes.isEmpty() ? null : stackHashes.removeFirst();
appendFirstLine(builder, prefix, indent, throwableProxy, hash);
appendStackTraceElements(builder, indent, throwableProxy);
IThrowableProxy[] suppressedThrowableProxies = throwableProxy.getSuppressed();
if (suppressedThrowableProxies != null) {
for (IThrowableProxy suppressedThrowableProxy : suppressedThrowableProxies) {
// stack hashes are not computed/inlined on suppressed errors
appendRootCauseLast(builder, CoreConstants.SUPPRESSED, indent + ThrowableProxyUtil.SUPPRESSED_EXCEPTION_INDENT, suppressedThrowableProxy, null);
}
}
appendRootCauseLast(builder, CoreConstants.CAUSED_BY, indent, throwableProxy.getCause(), stackHashes);
}
/**
* Appends a throwable and recursively appends its causedby/suppressed throwables
* in "reverse" order (Root cause first).
*/
private void appendRootCauseFirst(
StringBuilder builder,
String prefix,
int indent,
IThrowableProxy throwableProxy,
Deque<String> stackHashes) {
if (throwableProxy == null || builder.length() > maxLength) {
return;
}
if (throwableProxy.getCause() != null) {
appendRootCauseFirst(builder, prefix, indent, throwableProxy.getCause(), stackHashes);
prefix = CoreConstants.WRAPPED_BY;
}
String hash = stackHashes == null || stackHashes.isEmpty() ? null : stackHashes.removeLast();
appendFirstLine(builder, prefix, indent, throwableProxy, hash);
appendStackTraceElements(builder, indent, throwableProxy);
IThrowableProxy[] suppressedThrowableProxies = throwableProxy.getSuppressed();
if (suppressedThrowableProxies != null) {
for (IThrowableProxy suppressedThrowableProxy : suppressedThrowableProxies) {
// stack hashes are not computed/inlined on suppressed errors
appendRootCauseFirst(builder, CoreConstants.SUPPRESSED, indent + ThrowableProxyUtil.SUPPRESSED_EXCEPTION_INDENT, suppressedThrowableProxy, null);
}
}
}
/**
* Appends the frames of the throwable.
*/
private void appendStackTraceElements(StringBuilder builder, int indent, IThrowableProxy throwableProxy) {
if (builder.length() > maxLength) {
return;
}
StackTraceElementProxy[] stackTraceElements = throwableProxy.getStackTraceElementProxyArray();
int commonFrames = throwableProxy.getCommonFrames();
boolean appendingExcluded = false;
int consecutiveExcluded = 0;
int appended = 0;
StackTraceElementProxy previousWrittenStackTraceElement = null;
for (int i = 0; i < stackTraceElements.length - commonFrames; i++) {
if (maxDepthPerThrowable > 0 && appended >= maxDepthPerThrowable) {
/*
* We reached the configure limit. Bail out.
*/
appendPlaceHolder(builder, indent, stackTraceElements.length - commonFrames - maxDepthPerThrowable, "frames truncated");
break;
}
StackTraceElementProxy stackTraceElement = stackTraceElements[i];
if (i <= 1 || isIncluded(stackTraceElement)) {
/*
* We should append this line.
*
* consecutiveExcluded will be > 0 if we were previously skipping lines based on excludes
*/
if (consecutiveExcluded >= 2) {
/*
* Multiple consecutive lines were excluded, so append a placeholder
*/
appendPlaceHolder(builder, indent, consecutiveExcluded, "frames excluded");
consecutiveExcluded = 0;
} else if (consecutiveExcluded == 1) {
/*
* We only excluded one line, so just go back and include it
* instead of printing the excluding message for it.
*/
appendingExcluded = true;
consecutiveExcluded = 0;
i -= 2;
continue;
}
appendStackTraceElement(builder, indent, stackTraceElement, previousWrittenStackTraceElement);
previousWrittenStackTraceElement = stackTraceElement;
appendingExcluded = false;
appended++;
} else if (appendingExcluded) {
/*
* We're going back and appending something we previously excluded
*/
appendStackTraceElement(builder, indent, stackTraceElement, previousWrittenStackTraceElement);
previousWrittenStackTraceElement = stackTraceElement;
appended++;
} else {
consecutiveExcluded++;
}
}
if (consecutiveExcluded > 0) {
/*
* We were excluding stuff at the end, so append a placeholder
*/
appendPlaceHolder(builder, indent, consecutiveExcluded, "frames excluded");
}
if (commonFrames > 0) {
/*
* Common frames found, append a placeholder
*/
appendPlaceHolder(builder, indent, commonFrames, "common frames omitted");
}
}
/**
* Appends a placeholder indicating that some frames were not written.
*/
private void appendPlaceHolder(StringBuilder builder, int indent, int consecutiveExcluded, String message) {
indent(builder, indent);
builder.append(ELLIPSIS)
.append(" ")
.append(consecutiveExcluded)
.append(" ")
.append(message)
.append(CoreConstants.LINE_SEPARATOR);
}
/**
* Return true if the stack trace element is included (i.e. doesn't match any exclude patterns).
*/
private boolean isIncluded(StackTraceElementProxy step) {
return stackElementFilter.accept(step.getStackTraceElement());
}
/**
* Appends a single stack trace element.
*/
private void appendStackTraceElement(StringBuilder builder, int indent, StackTraceElementProxy step, StackTraceElementProxy previousStep) {
if (builder.length() > maxLength) {
return;
}
indent(builder, indent);
StackTraceElement stackTraceElement = step.getStackTraceElement();
String fileName = stackTraceElement.getFileName();
int lineNumber = stackTraceElement.getLineNumber();
builder.append("at ")
.append(abbreviator.abbreviate(stackTraceElement.getClassName()))
.append(".")
.append(stackTraceElement.getMethodName())
.append("(")
.append(fileName == null ? "Unknown Source" : fileName);
if (lineNumber >= 0) {
builder.append(":")
.append(lineNumber);
}
builder.append(")");
if (shouldAppendPackagingData(step, previousStep)) {
appendPackagingData(builder, step);
}
builder.append(CoreConstants.LINE_SEPARATOR);
}
/**
* Return true if packaging data should be appended for the current step.
*
* Packaging data for the current step is only appended if it differs
* from the packaging data from the previous step.
*/
private boolean shouldAppendPackagingData(StackTraceElementProxy step, StackTraceElementProxy previousStep) {
if (step == null || step.getClassPackagingData() == null) {
return false;
}
if (previousStep == null || previousStep.getClassPackagingData() == null) {
return true;
}
return !step.getClassPackagingData().equals(previousStep.getClassPackagingData());
}
private void appendPackagingData(StringBuilder builder, StackTraceElementProxy step) {
ThrowableProxyUtil.subjoinPackagingData(builder, step);
}
/**
* Appends the first line containing the prefix and throwable message
*/
private void appendFirstLine(StringBuilder builder, String prefix, int indent, IThrowableProxy throwableProxy, String hash) {
if (builder.length() > maxLength) {
return;
}
indent(builder, indent - 1);
if (prefix != null) {
builder.append(prefix);
}
if (hash != null) {
// inline stack hash
builder.append("<#" + hash + "> ");
}
builder.append(abbreviator.abbreviate(throwableProxy.getClassName()))
.append(": ")
.append(throwableProxy.getMessage())
.append(CoreConstants.LINE_SEPARATOR);
}
private void indent(StringBuilder builder, int indent) {
ThrowableProxyUtil.indent(builder, indent);
}
public int getShortenedClassNameLength() {
return shortenedClassNameLength;
}
public void setShortenedClassNameLength(int length) {
if (length <= 0) {
throw new IllegalArgumentException();
}
this.shortenedClassNameLength = length;
if (length < FULL_CLASS_NAME_LENGTH) {
abbreviator = new CachingAbbreviator(new TargetLengthBasedClassNameAbbreviator(this.shortenedClassNameLength));
} else {
abbreviator = NullAbbreviator.INSTANCE;
}
}
public int getMaxDepthPerThrowable() {
return maxDepthPerThrowable;
}
public void setMaxDepthPerThrowable(int maxDepthPerThrowable) {
if (maxDepthPerThrowable <= 0) {
throw new IllegalArgumentException();
}
this.maxDepthPerThrowable = maxDepthPerThrowable;
}
public void setMaxLength(int maxLength) {
if (maxLength <= 0) {
throw new IllegalArgumentException();
}
this.maxLength = maxLength;
}
public int getMaxLength() {
return maxLength;
}
public boolean isRootCauseFirst() {
return rootCauseFirst;
}
public void setRootCauseFirst(boolean rootCauseFirst) {
this.rootCauseFirst = rootCauseFirst;
}
public boolean isInlineHash() {
return inlineHash;
}
public void setInlineHash(boolean inlineHash) {
this.inlineHash = inlineHash;
}
protected void setStackHasher(StackHasher stackHasher) {
this.stackHasher = stackHasher;
}
public void addExclude(String exclusionPattern) {
excludes.add(Pattern.compile(exclusionPattern));
}
/**
* Set exclusion patterns as a list of coma separated patterns
* @param comaSeparatedPatterns list of coma separated patterns
*/
public void setExclusions(String comaSeparatedPatterns) {
if (comaSeparatedPatterns == null || comaSeparatedPatterns.isEmpty()) {
this.excludes = new ArrayList<Pattern>(5);
} else {
setExcludes(Arrays.asList(comaSeparatedPatterns.split("\\s*\\,\\s*")));
}
}
public void setExcludes(List<String> exclusionPatterns) {
if (exclusionPatterns == null || exclusionPatterns.isEmpty()) {
this.excludes = new ArrayList<Pattern>(5);
} else {
this.excludes = new ArrayList<Pattern>(exclusionPatterns.size());
for (String pattern : exclusionPatterns) {
addExclude(pattern);
}
}
}
public List<String> getExcludes() {
List<String> exclusionPatterns = new ArrayList<String>(excludes.size());
for (Pattern pattern : excludes) {
exclusionPatterns.add(pattern.pattern());
}
return exclusionPatterns;
}
public void addEvaluator(EventEvaluator<ILoggingEvent> evaluator) {
evaluators.add(evaluator);
}
public void setEvaluators(List<EventEvaluator<ILoggingEvent>> evaluators) {
if (evaluators == null || evaluators.isEmpty()) {
this.evaluators = new ArrayList<EventEvaluator<ILoggingEvent>>(1);
} else {
this.evaluators = new ArrayList<EventEvaluator<ILoggingEvent>>(evaluators);
}
}
public List<EventEvaluator<ILoggingEvent>> getEvaluators() {
return new ArrayList<EventEvaluator<ILoggingEvent>>(evaluators);
}
}