logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1515465 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/appender/ core/src/main/java/org/apache/logging/log4j/core/config/ core/src/main/java/org/apache/logging/log4j/core/config/plugins/ core/src/test/re...
Date Mon, 19 Aug 2013 15:21:37 GMT
Author: rgoers
Date: Mon Aug 19 15:21:36 2013
New Revision: 1515465

URL: http://svn.apache.org/r1515465
Log:
LOG4J2-360 - Allow Plugins to have aliases. Create aliases for AppenderRef and ErrorRef

Added:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
      - copied, changed from r1514947, logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-asynch.xml
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
Mon Aug 19 15:21:36 2013
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
@@ -166,7 +167,7 @@ public final class AsyncAppender extends
     @PluginFactory
     public static AsyncAppender createAppender(
                 @PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
-                @PluginAttr("errorRef") final String errorRef,
+                @PluginAttr("errorRef") @PluginAliases("error-ref") final String errorRef,
                 @PluginAttr("blocking") final String blocking,
                 @PluginAttr("bufferSize") final String size,
                 @PluginAttr("name") final String name,

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java
Mon Aug 19 15:21:36 2013
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
@@ -29,6 +30,7 @@ import org.apache.logging.log4j.status.S
  * An Appender reference.
  */
 @Plugin(name = "AppenderRef", category = "Core", printObject = true)
+@PluginAliases("appender-ref")
 public final class AppenderRef {
     private static final Logger LOGGER = StatusLogger.getLogger();
 
@@ -54,6 +56,11 @@ public final class AppenderRef {
         return filter;
     }
 
+    @Override
+    public String toString() {
+        return ref;
+    }
+
     /**
      * Create an Appender reference.
      * @param ref The name of the Appender.

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
Mon Aug 19 15:21:36 2013
@@ -36,6 +36,7 @@ import org.apache.logging.log4j.core.Fil
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
@@ -635,7 +636,16 @@ public class BaseConfiguration extends A
          *   If not an array, store the object in the child node into the parameter array.
          */
         for (final Annotation[] parmTypes : parmArray) {
+            String[] aliases = null;
+            for (final Annotation a: parmTypes) {
+                if (a instanceof PluginAliases) {
+                    aliases = ((PluginAliases) a).value();
+                }
+            }
             for (final Annotation a : parmTypes) {
+                if (a instanceof PluginAliases) {
+                    continue;
+                }
                 if (sb.length() == 0) {
                     sb.append(" with params(");
                 } else {
@@ -655,14 +665,15 @@ public class BaseConfiguration extends A
                     final String name = ((PluginValue) a).value();
                     String v = node.getValue();
                     if (v == null) {
-                        v = getAttrValue("value", attrs);
+                        v = getAttrValue("value", null, attrs);
                     }
                     final String value = subst.replace(event, v);
                     sb.append(name).append("=\"").append(value).append("\"");
                     parms[index] = value;
                 } else if (a instanceof PluginAttr) {
-                    final String name = ((PluginAttr) a).value();
-                    final String value = subst.replace(event, getAttrValue(name, attrs));
+                    PluginAttr attr = (PluginAttr) a;
+                    final String name = attr.value();
+                    final String value = subst.replace(event, getAttrValue(name, aliases,
attrs));
                     sb.append(name).append("=\"").append(value).append("\"");
                     parms[index] = value;
                 } else if (a instanceof PluginElement) {
@@ -804,13 +815,22 @@ public class BaseConfiguration extends A
         }
     }
 
-    private String getAttrValue(final String name, final Map<String, String> attrs)
{
+    private String getAttrValue(final String name, final String[] aliases, final Map<String,
String> attrs) {
         for (final String key : attrs.keySet()) {
             if (key.equalsIgnoreCase(name)) {
                 final String attr = attrs.get(key);
                 attrs.remove(key);
                 return attr;
             }
+            if (aliases != null) {
+                for (String alias : aliases) {
+                    if (key.equalsIgnoreCase(alias)) {
+                        final String attr = attrs.get(key);
+                        attrs.remove(key);
+                        return attr;
+                    }
+                }
+            }
         }
         return null;
     }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
Mon Aug 19 15:21:36 2013
@@ -73,7 +73,7 @@ public class XMLConfiguration extends Ba
 
     /**
      * Creates a new DocumentBuilder suitable for parsing a configuration file.
-     * 
+     *
      * @return a new DocumentBuilder
      * @throws ParserConfigurationException
      */
@@ -87,7 +87,7 @@ public class XMLConfiguration extends Ba
 
     /**
      * Enables XInclude for the given DocumentBuilderFactory
-     * 
+     *
      * @param factory
      *            a DocumentBuilderFactory
      * @throws ParserConfigurationException
@@ -345,7 +345,8 @@ public class XMLConfiguration extends Ba
             if (w3cNode instanceof Element) {
                 final Element child = (Element) w3cNode;
                 final String name = getType(child);
-                final PluginType<?> type = getPluginManager().getPluginType(name);
+                PluginManager mgr = getPluginManager();
+                final PluginType<?> type = mgr.getPluginType(name);
                 final Node childNode = new Node(node, name, type);
                 constructHierarchy(childNode, child);
                 if (type == null) {

Copied: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
(from r1514947, logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java?p2=logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java&p1=logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java&r1=1514947&r2=1515465&rev=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
Mon Aug 19 15:21:36 2013
@@ -25,8 +25,8 @@ import java.lang.annotation.Target;
  * Identifies a Plugin Attribute.
  */
 @Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.PARAMETER)
-public @interface PluginAttr {
+@Target({ElementType.PARAMETER, ElementType.TYPE})
+public @interface PluginAliases {
 
-    String value();
+    String[] value();
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
Mon Aug 19 15:21:36 2013
@@ -174,14 +174,22 @@ public class PluginManager {
         }
         for (final Class<?> clazz : resolver.getClasses()) {
             final Plugin plugin = clazz.getAnnotation(Plugin.class);
-            final String pluginType = plugin.category();
-            if (!pluginTypeMap.containsKey(pluginType)) {
-                pluginTypeMap.putIfAbsent(pluginType, new ConcurrentHashMap<String, PluginType<?>>());
-            }
-            final Map<String, PluginType<?>> map = pluginTypeMap.get(pluginType);
-            final String type = plugin.elementType().equals(Plugin.EMPTY) ? plugin.name()
: plugin.elementType();
-            map.put(plugin.name().toLowerCase(), new PluginType(clazz, type, plugin.printObject(),
-                plugin.deferChildren()));
+            final String pluginCategory = plugin.category();
+            if (!pluginTypeMap.containsKey(pluginCategory)) {
+                pluginTypeMap.putIfAbsent(pluginCategory, new ConcurrentHashMap<String,
PluginType<?>>());
+            }
+            final Map<String, PluginType<?>> map = pluginTypeMap.get(pluginCategory);
+            String type = plugin.elementType().equals(Plugin.EMPTY) ? plugin.name() : plugin.elementType();
+            PluginType pluginType = new PluginType(clazz, type, plugin.printObject(), plugin.deferChildren());
+            map.put(plugin.name().toLowerCase(), pluginType);
+            final PluginAliases pluginAliases = clazz.getAnnotation(PluginAliases.class);
+            if (pluginAliases != null) {
+                for (String alias : pluginAliases.value()) {
+                    type =  plugin.elementType().equals(Plugin.EMPTY) ? alias : plugin.elementType();
+                    pluginType = new PluginType(clazz, type, plugin.printObject(), plugin.deferChildren());
+                    map.put(alias.trim().toLowerCase(), pluginType);
+                }
+            }
         }
         long elapsed = System.nanoTime() - start;
         plugins = pluginTypeMap.get(type);

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-asynch.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-asynch.xml?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-asynch.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-asynch.xml Mon Aug 19 15:21:36
2013
@@ -25,7 +25,7 @@
     <List name="List">
       <PatternLayout pattern="%C %M %m"/>
     </List>
-    <Async name="Async" includeLocation="true">
+    <Async name="Async" includeLocation="true" error-ref="STDOUT">
       <AppenderRef ref="List"/>
     </Async>
   </Appenders>

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml Mon Aug 19 15:21:36
2013
@@ -61,7 +61,8 @@
     </Logger>>
 
     <Logger name="org.apache.logging.log4j.hosttest" level="debug" additivity="false">
-      <AppenderRef ref="HostTest"/>
+      <!-- User appender-ref alias to prove it works -->
+      <appender-ref ref="HostTest"/>
     </Logger>
 
 

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1515465&r1=1515464&r2=1515465&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Mon Aug 19 15:21:36 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-360" dev="rgoers" type="update">
+        Allow Plugins to have aliases.
+      </action>
       <action issue="LOG4J2-358" dev="nickwilliams" type="fix">
         NoSQLAppender using MongoDB provider ignores username and password attributes
       </action>



Mime
View raw message