Repository: logging-log4j2
Updated Branches:
  refs/heads/master f5e4d2907 -> ce9a8f871


Use @Required and actual attribute type in plugin factory


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ce9a8f87
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ce9a8f87
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ce9a8f87

Branch: refs/heads/master
Commit: ce9a8f8710ac389f2bbc03840ad48c06c79afafa
Parents: f5e4d29
Author: Matt Sicker <boa...@gmail.com>
Authored: Sun Mar 6 17:13:15 2016 -0600
Committer: Matt Sicker <boa...@gmail.com>
Committed: Sun Mar 6 17:13:15 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/core/config/LoggerConfig.java | 34 +++++++++++++++++++-
 .../core/config/CustomConfigurationTest.java    |  2 +-
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce9a8f87/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index 1cd0451..e5eb9d4 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -35,6 +35,7 @@ import 
org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import 
org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
 import org.apache.logging.log4j.core.filter.AbstractFilterable;
 import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
@@ -404,8 +405,9 @@ public class LoggerConfig extends AbstractFilterable {
      * @param config The Configuration.
      * @param filter A Filter.
      * @return A new LoggerConfig.
+     * @deprecated Use {@link #createLogger(boolean, Level, String, String, 
AppenderRef[], Property[], Configuration, Filter)}
      */
-    @PluginFactory
+    @Deprecated
     public static LoggerConfig createLogger(@PluginAttribute("additivity") 
final String additivity,
             @PluginAttribute("level") final Level level, 
@PluginAttribute("name") final String loggerName,
             @PluginAttribute("includeLocation") final String includeLocation,
@@ -425,6 +427,36 @@ public class LoggerConfig extends AbstractFilterable {
                 includeLocation(includeLocation));
     }
 
+    /**
+     * Factory method to create a LoggerConfig.
+     *
+     * @param additivity True if additive, false otherwise.
+     * @param level The Level to be associated with the Logger.
+     * @param loggerName The name of the Logger.
+     * @param includeLocation whether location should be passed downstream
+     * @param refs An array of Appender names.
+     * @param properties Properties to pass to the Logger.
+     * @param config The Configuration.
+     * @param filter A Filter.
+     * @return A new LoggerConfig.
+     * @since 2.6
+     */
+    @PluginFactory
+    public static LoggerConfig createLogger(
+        @PluginAttribute(value = "additivity", defaultBoolean = true) final 
boolean additivity,
+        @PluginAttribute("level") final Level level,
+        @Required(message = "Loggers cannot be configured without a name") 
@PluginAttribute("name") final String loggerName,
+        @PluginAttribute("includeLocation") final String includeLocation,
+        @PluginElement("AppenderRef") final AppenderRef[] refs,
+        @PluginElement("Properties") final Property[] properties,
+        @PluginConfiguration final Configuration config,
+        @PluginElement("Filter") final Filter filter
+    ) {
+        final String name = loggerName.equals(ROOT) ? Strings.EMPTY : 
loggerName;
+        return new LoggerConfig(name, Arrays.asList(refs), filter, level, 
additivity, properties, config,
+            includeLocation(includeLocation));
+    }
+
     // Note: for asynchronous loggers, includeLocation default is FALSE,
     // for synchronous loggers, includeLocation default is TRUE.
     protected static boolean includeLocation(final String 
includeLocationConfigValue) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce9a8f87/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
index 136686c..b8dad5e 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
@@ -87,7 +87,7 @@ public class CustomConfigurationTest {
         final AppenderRef ref = AppenderRef.createAppenderRef("File", null, 
null);
         final AppenderRef[] refs = new AppenderRef[] {ref};
 
-        final LoggerConfig loggerConfig = LoggerConfig.createLogger("false", 
Level.INFO, "org.apache.logging.log4j",
+        final LoggerConfig loggerConfig = LoggerConfig.createLogger(false, 
Level.INFO, "org.apache.logging.log4j",
             "true", refs, null, config, null );
         loggerConfig.addAppender(appender, null, null);
         config.addLogger("org.apache.logging.log4j", loggerConfig);

Reply via email to