|
16 | 16 | */
|
17 | 17 | package org.apache.logging.log4j.core.filter;
|
18 | 18 |
|
| 19 | +import java.util.Objects; |
| 20 | +import java.util.Optional; |
19 | 21 | import org.apache.logging.log4j.Level;
|
20 | 22 | import org.apache.logging.log4j.Marker;
|
21 | 23 | import org.apache.logging.log4j.core.AbstractLifeCycle;
|
@@ -43,16 +45,30 @@ public abstract static class AbstractFilterBuilder<B extends AbstractFilterBuild
|
43 | 45 | public static final String ATTR_ON_MISMATCH = "onMismatch";
|
44 | 46 | public static final String ATTR_ON_MATCH = "onMatch";
|
45 | 47 |
|
| 48 | + /** |
| 49 | + * The action to perform when a match occurs. |
| 50 | + */ |
46 | 51 | @PluginBuilderAttribute(ATTR_ON_MATCH)
|
47 |
| - private Result onMatch = Result.NEUTRAL; |
| 52 | + protected Result onMatch = Result.NEUTRAL; |
48 | 53 |
|
| 54 | + /** |
| 55 | + * The action to perform when a mismatch occurs. |
| 56 | + */ |
49 | 57 | @PluginBuilderAttribute(ATTR_ON_MISMATCH)
|
50 |
| - private Result onMismatch = Result.DENY; |
| 58 | + protected Result onMismatch = Result.DENY; |
51 | 59 |
|
| 60 | + /** |
| 61 | + * Returns the action to apply when a match occurs |
| 62 | + * @return the match result |
| 63 | + */ |
52 | 64 | public Result getOnMatch() {
|
53 | 65 | return onMatch;
|
54 | 66 | }
|
55 | 67 |
|
| 68 | + /** |
| 69 | + * Returns the action to apply when a mismatch occurs |
| 70 | + * @return the mismatch result |
| 71 | + */ |
56 | 72 | public Result getOnMismatch() {
|
57 | 73 | return onMismatch;
|
58 | 74 | }
|
@@ -110,6 +126,19 @@ protected AbstractFilter(final Result onMatch, final Result onMismatch) {
|
110 | 126 | this.onMismatch = onMismatch == null ? Result.DENY : onMismatch;
|
111 | 127 | }
|
112 | 128 |
|
| 129 | + /** |
| 130 | + * Constructs a new instance configured by the given builder |
| 131 | + * @param builder the builder |
| 132 | + * @throws NullPointerException if the builder argument is {@code null} |
| 133 | + */ |
| 134 | + protected AbstractFilter(final AbstractFilterBuilder<?> builder) { |
| 135 | + |
| 136 | + Objects.requireNonNull(builder, "The 'builder' argument cannot be null."); |
| 137 | + |
| 138 | + this.onMatch = Optional.ofNullable(builder.onMatch).orElse(Result.NEUTRAL); |
| 139 | + this.onMismatch = Optional.ofNullable(builder.onMismatch).orElse(Result.DENY); |
| 140 | + } |
| 141 | + |
113 | 142 | @Override
|
114 | 143 | protected boolean equalsImpl(final Object obj) {
|
115 | 144 | if (this == obj) {
|
|
0 commit comments