LOG4J2-1526 Possibility to set StatusLogger destination in ConfigurationBuilder
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f271b30a Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f271b30a Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f271b30a Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure Commit: f271b30ab9222cdb8db3b77d387795faa7cdd9da Parents: 9d42011 Author: Mikael Ståldal <mik...@staldal.nu> Authored: Wed Aug 17 21:44:11 2016 +0200 Committer: Mikael Ståldal <mik...@staldal.nu> Committed: Wed Aug 17 21:44:11 2016 +0200 ---------------------------------------------------------------------- .../core/config/builder/api/ConfigurationBuilder.java | 12 +++++++++++- .../builder/impl/DefaultConfigurationBuilder.java | 10 ++++++++++ .../properties/PropertiesConfigurationBuilder.java | 2 ++ .../src/test/resources/log4j2-properties.properties | 1 + src/changes/changes.xml | 3 +++ src/site/xdoc/manual/configuration.xml.vm | 3 ++- 6 files changed, 29 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f271b30a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java index 629b9c9..1fbfa01 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java @@ -324,7 +324,6 @@ public interface ConfigurationBuilder<T extends Configuration> extends Builder<T /** * Set the Advertiser Plugin name. * @param advertiser The Advertiser Plugin name. - * @param includeLocation If true include location information. * @return this builder instance. */ ConfigurationBuilder<T> setAdvertiser(String advertiser); @@ -381,6 +380,17 @@ public interface ConfigurationBuilder<T extends Configuration> extends Builder<T ConfigurationBuilder<T> setVerbosity(String verbosity); /** + * Specifies the destination for StatusLogger events. This can be {@code out} (default) for using + * {@link System#out standard out}, {@code err} for using {@link System#err standard error}, or a file URI to + * which log events will be written. If the provided URI is invalid, then the default destination of standard + * out will be used. + * + * @param destination where status log messages should be output. + * @return this builder instance. + */ + ConfigurationBuilder<T> setDestination(String destination); + + /** * Add the properties for the root node. * @param key The property key. * @param value The property value. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f271b30a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java index e26407a..38b4fdb 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java @@ -56,6 +56,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement private int monitorInterval = 0; private Level level = null; private String verbosity = null; + private String destination = null; private String packages = null; private String shutdownFlag = null; private String advertiser = null; @@ -164,6 +165,9 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement if (verbosity != null) { configuration.getStatusConfiguration().withVerbosity(verbosity); } + if (destination != null) { + configuration.getStatusConfiguration().withDestination(destination); + } if (packages != null) { configuration.setPluginPackages(packages); } @@ -390,6 +394,12 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override + public ConfigurationBuilder<T> setDestination(String destination) { + this.destination = destination; + return this; + } + + @Override public ConfigurationBuilder<T> addRootProperty(final String key, final String value) { root.getAttributes().put(key, value); return this; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f271b30a/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 0f159ff..d9245ad 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 @@ -54,6 +54,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory private static final String STATUS_KEY = "status"; private static final String SHUTDOWN_HOOK = "shutdownHook"; private static final String VERBOSE = "verbose"; + private static final String DEST = "dest"; private static final String PACKAGES = "packages"; private static final String CONFIG_NAME = "name"; private static final String MONITOR_INTERVAL = "monitorInterval"; @@ -88,6 +89,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory .setStatusLevel(Level.toLevel(rootProperties.getProperty(STATUS_KEY), Level.ERROR)) .setShutdownHook(rootProperties.getProperty(SHUTDOWN_HOOK)) .setVerbosity(rootProperties.getProperty(VERBOSE)) + .setDestination(rootProperties.getProperty(DEST)) .setPackages(rootProperties.getProperty(PACKAGES)) .setConfigurationName(rootProperties.getProperty(CONFIG_NAME)) .setMonitorInterval(rootProperties.getProperty(MONITOR_INTERVAL, "0")) http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f271b30a/log4j-core/src/test/resources/log4j2-properties.properties ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/resources/log4j2-properties.properties b/log4j-core/src/test/resources/log4j2-properties.properties index c446d82..a6517b7 100644 --- a/log4j-core/src/test/resources/log4j2-properties.properties +++ b/log4j-core/src/test/resources/log4j2-properties.properties @@ -14,6 +14,7 @@ # limitations under the License. status = ERROR +dest = err filter.Threshold.type = ThresholdFilter filter.Threshold.level = DEBUG http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f271b30a/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5bf647c..ccf3181 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -24,6 +24,9 @@ </properties> <body> <release version="2.7" date="2016-MM-DD" description="GA Release 2.7"> + <action issue="LOG4J2-1526" dev="mikes" type="fix"> + Possibility to set StatusLogger destination in ConfigurationBuilder. + </action> <action issue="LOG4J2-1448" dev="rpopma" type="fix" due-to="Keith Laban"> Allow comma separated agents, host list to be passed to FlumeAppender. </action> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f271b30a/src/site/xdoc/manual/configuration.xml.vm ---------------------------------------------------------------------- diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm index ac386ed..246baf4 100644 --- a/src/site/xdoc/manual/configuration.xml.vm +++ b/src/site/xdoc/manual/configuration.xml.vm @@ -841,11 +841,12 @@ public class Bar { </p> <p> Properties configuration files support the advertiser, monitorInterval, name, packages, shutdownHook, - status, and verbose attrbutes. See <a href="#ConfigurationSyntax">Configuration Syntax</a> for the + status, verbose, and dest attrbutes. See <a href="#ConfigurationSyntax">Configuration Syntax</a> for the definitions of these attributes. </p> <pre class="prettyprint linenums"> status = error +dest = err name = PropertiesConfig property.filename = target/rolling/rollingtest.log