Repository: logging-log4j2 Updated Branches: refs/heads/master 989d894c1 -> 33956aa61
[LOG4J2-2219] Configuration builder classes should look for "onMismatch", not "onMisMatch". Related to [LOG4J2-2202]. Also refactor to use an abstract filter builder. Refactor to centralize the definition of "onMatch" and "onMismatch" Strings. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33956aa6 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33956aa6 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33956aa6 Branch: refs/heads/master Commit: 33956aa616ad73b5dc951e4cd5e358390d61e8f9 Parents: 989d894 Author: Gary Gregory <[email protected]> Authored: Wed Jan 24 13:46:52 2018 -0700 Committer: Gary Gregory <[email protected]> Committed: Wed Jan 24 13:46:52 2018 -0700 ---------------------------------------------------------------------- .../DefaultCompositeFilterComponentBuilder.java | 5 ++- .../impl/DefaultFilterComponentBuilder.java | 5 ++- .../PropertiesConfigurationBuilder.java | 6 +-- .../log4j/core/filter/AbstractFilter.java | 47 ++++++++++++++++++++ .../logging/log4j/core/filter/BurstFilter.java | 34 ++++---------- .../logging/log4j/core/filter/MarkerFilter.java | 7 +-- src/changes/changes.xml | 3 ++ 7 files changed, 70 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultCompositeFilterComponentBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultCompositeFilterComponentBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultCompositeFilterComponentBuilder.java index 6c7aedd..86ccd2b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultCompositeFilterComponentBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultCompositeFilterComponentBuilder.java @@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.config.builder.impl; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.builder.api.CompositeFilterComponentBuilder; import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder; +import org.apache.logging.log4j.core.filter.AbstractFilter.AbstractFilterBuilder; /** * @since 2.4 @@ -30,8 +31,8 @@ class DefaultCompositeFilterComponentBuilder public DefaultCompositeFilterComponentBuilder(final DefaultConfigurationBuilder<? extends Configuration> builder, final String onMatch, final String onMismatch) { super(builder, "Filters"); - addAttribute("onMatch", onMatch); - addAttribute("onMisMatch", onMismatch); + addAttribute(AbstractFilterBuilder.ATTR_ON_MATCH, onMatch); + addAttribute(AbstractFilterBuilder.ATTR_ON_MISMATCH, onMismatch); } @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultFilterComponentBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultFilterComponentBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultFilterComponentBuilder.java index 9589672..89b69f6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultFilterComponentBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultFilterComponentBuilder.java @@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.config.builder.impl; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder; +import org.apache.logging.log4j.core.filter.AbstractFilter.AbstractFilterBuilder; /** * @since 2.4 @@ -28,7 +29,7 @@ class DefaultFilterComponentBuilder extends DefaultComponentAndConfigurationBuil public DefaultFilterComponentBuilder(final DefaultConfigurationBuilder<? extends Configuration> builder, final String type, final String onMatch, final String onMismatch) { super(builder, type); - addAttribute("onMatch", onMatch); - addAttribute("onMisMatch", onMismatch); + addAttribute(AbstractFilterBuilder.ATTR_ON_MATCH, onMatch); + addAttribute(AbstractFilterBuilder.ATTR_ON_MISMATCH, onMismatch); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java index 9fab7a4..3143259 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java @@ -40,7 +40,7 @@ import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder; import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; import org.apache.logging.log4j.core.config.builder.api.ScriptComponentBuilder; import org.apache.logging.log4j.core.config.builder.api.ScriptFileComponentBuilder; -import org.apache.logging.log4j.core.filter.MarkerFilter; +import org.apache.logging.log4j.core.filter.AbstractFilter.AbstractFilterBuilder; import org.apache.logging.log4j.core.util.Builder; import org.apache.logging.log4j.util.PropertiesUtil; import org.apache.logging.log4j.util.Strings; @@ -230,8 +230,8 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory if (Strings.isEmpty(type)) { throw new ConfigurationException("No type attribute provided for Appender " + key); } - final String onMatch = (String) properties.remove(MarkerFilter.ATTR_ON_MATCH); - final String onMismatch = (String) properties.remove(MarkerFilter.ATTR_ON_MISMATCH); + final String onMatch = (String) properties.remove(AbstractFilterBuilder.ATTR_ON_MATCH); + final String onMismatch = (String) properties.remove(AbstractFilterBuilder.ATTR_ON_MISMATCH); final FilterComponentBuilder filterBuilder = builder.newFilter(type, onMatch, onMismatch); return processRemainingProperties(filterBuilder, properties); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/AbstractFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/AbstractFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/AbstractFilter.java index b27b238..5e3c133 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/AbstractFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/AbstractFilter.java @@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.AbstractLifeCycle; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.message.Message; /** @@ -37,6 +38,52 @@ import org.apache.logging.log4j.message.Message; */ public abstract class AbstractFilter extends AbstractLifeCycle implements Filter { + public static abstract class AbstractFilterBuilder<B extends AbstractFilterBuilder<B>> { + + public static final String ATTR_ON_MISMATCH = "onMismatch"; + public static final String ATTR_ON_MATCH = "onMatch"; + + @PluginBuilderAttribute(ATTR_ON_MATCH) + private Result onMatch = Result.NEUTRAL; + + @PluginBuilderAttribute(ATTR_ON_MISMATCH) + private Result onMismatch = Result.DENY; + + public Result getOnMatch() { + return onMatch; + } + + public Result getOnMismatch() { + return onMismatch; + } + + /** + * Sets the Result to return when the filter matches. Defaults to Result.NEUTRAL. + * @param onMatch the Result to return when the filter matches. + * @return this + */ + public B setOnMatch(final Result onMatch) { + this.onMatch = onMatch; + return asBuilder(); + } + + /** + * Sets the Result to return when the filter does not match. The default is Result.DENY. + * @param onMismatch the Result to return when the filter does not match. + * @return this + */ + public B setOnMismatch(final Result onMismatch) { + this.onMismatch = onMismatch; + return asBuilder(); + } + + @SuppressWarnings("unchecked") + public B asBuilder() { + return (B) this; + } + + } + /** * The onMatch Result. */ http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java index f59dca7..c2326ad 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java @@ -290,7 +290,7 @@ public final class BurstFilter extends AbstractFilter { return new Builder(); } - public static class Builder implements org.apache.logging.log4j.core.util.Builder<BurstFilter> { + public static class Builder extends AbstractFilterBuilder<Builder> implements org.apache.logging.log4j.core.util.Builder<BurstFilter> { @PluginBuilderAttribute private Level level = Level.WARN; @@ -301,14 +301,10 @@ public final class BurstFilter extends AbstractFilter { @PluginBuilderAttribute private long maxBurst; - @PluginBuilderAttribute - private Result onMatch = Result.NEUTRAL; - - @PluginBuilderAttribute - private Result onMismatch = Result.DENY; - /** * Sets the logging level to use. + * @param level the logging level to use. + * @return this */ public Builder setLevel(final Level level) { this.level = level; @@ -316,7 +312,9 @@ public final class BurstFilter extends AbstractFilter { } /** - * Sets the average number of events per second to allow. This must be a positive number. + * Sets the average number of events per second to allow. + * @param rate the average number of events per second to allow. This must be a positive number. + * @return this */ public Builder setRate(final float rate) { this.rate = rate; @@ -325,29 +323,15 @@ public final class BurstFilter extends AbstractFilter { /** * Sets the maximum number of events that can occur before events are filtered for exceeding the average rate. + * @param maxBurst Sets the maximum number of events that can occur before events are filtered for exceeding the average rate. * The default is 10 times the rate. + * @return this */ public Builder setMaxBurst(final long maxBurst) { this.maxBurst = maxBurst; return this; } - /** - * Sets the Result to return when the filter matches. Defaults to Result.NEUTRAL. - */ - public Builder setOnMatch(final Result onMatch) { - this.onMatch = onMatch; - return this; - } - - /** - * Sets the Result to return when the filter does not match. The default is Result.DENY. - */ - public Builder setOnMismatch(final Result onMismatch) { - this.onMismatch = onMismatch; - return this; - } - @Override public BurstFilter build() { if (this.rate <= 0) { @@ -356,7 +340,7 @@ public final class BurstFilter extends AbstractFilter { if (this.maxBurst <= 0) { this.maxBurst = (long) (this.rate * DEFAULT_RATE_MULTIPLE); } - return new BurstFilter(this.level, this.rate, this.maxBurst, this.onMatch, this.onMismatch); + return new BurstFilter(this.level, this.rate, this.maxBurst, this.getOnMatch(), this.getOnMismatch()); } } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java index 1774544..3950bc9 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java @@ -37,9 +37,6 @@ import org.apache.logging.log4j.util.PerformanceSensitive; public final class MarkerFilter extends AbstractFilter { public static final String ATTR_MARKER = "marker"; - public static final String ATTR_ON_MATCH = "onMatch"; - public static final String ATTR_ON_MISMATCH = "onMismatch"; - private final String name; private MarkerFilter(final String name, final Result onMatch, final Result onMismatch) { @@ -158,8 +155,8 @@ public final class MarkerFilter extends AbstractFilter { @PluginFactory public static MarkerFilter createFilter( @PluginAttribute(ATTR_MARKER) final String marker, - @PluginAttribute(ATTR_ON_MATCH) final Result match, - @PluginAttribute(ATTR_ON_MISMATCH) final Result mismatch) { + @PluginAttribute(AbstractFilterBuilder.ATTR_ON_MATCH) final Result match, + @PluginAttribute(AbstractFilterBuilder.ATTR_ON_MISMATCH) final Result mismatch) { if (marker == null) { LOGGER.error("A marker must be provided for MarkerFilter"); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33956aa6/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index fc4f8fe..ed028c1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -149,6 +149,9 @@ <action issue="LOG4J2-2202" dev="ggregory" type="update" due-to="Kilian, Gary Gregory"> MarkerFilter onMismatch invalid attribute in .properties. </action> + <action issue="LOG4J2-2219" dev="ggregory" type="update" due-to="Kilian, Gary Gregory"> + Configuration builder classes should look for "onMismatch", not "onMisMatch". + </action> <!-- <action issue="LOG4J2-2205" dev="ggregory" type="update" due-to="Björn Kautler"> New module log4j-mongodb3: Remove use of deprecated MongoDB APIs and code to the Java driver version 3 API.
