Author: sdeboy
Date: Thu Mar 14 05:14:38 2013
New Revision: 1456325
URL: http://svn.apache.org/r1456325
Log:
Implementing LOG4J2-155: add getFormat to Layout
Advertiser implementations are now a 'Core' type with an 'advertiser'
elementType.
Updated XMLConfiguration and JSONConfiguration to resolve the 'advertiser'
attribute on the configuration element via the plugin mechanism
The test in-memory advertiser is now defined as 'memory' in the test xml
config, and the multicast DNS implementation can be defined as 'multicastdns'
Also updated the packages definition on the log4j-advertiser.xml to include the
'core' package, as the in-memory advertiser is in the 'core' package hierarchy
(depended on the fix for LOG4J2-175)
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultAdvertiser.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.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/net/MulticastDNSAdvertiser.java
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-advertiser.xml
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultAdvertiser.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultAdvertiser.java?rev=1456325&r1=1456324&r2=1456325&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultAdvertiser.java
(original)
+++
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultAdvertiser.java
Thu Mar 14 05:14:38 2013
@@ -16,6 +16,7 @@
*/
package org.apache.logging.log4j.core.config;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.net.Advertiser;
import java.util.Map;
@@ -23,6 +24,7 @@ import java.util.Map;
/**
* The default advertiser does not do anything.
*/
+@Plugin(name = "default", type = "Core", elementType = "advertiser",
printObject = false)
public class DefaultAdvertiser implements Advertiser {
/**
* Does nothing.
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java?rev=1456325&r1=1456324&r2=1456325&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
(original)
+++
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
Thu Mar 14 05:14:38 2013
@@ -118,8 +118,14 @@ public class JSONConfiguration extends B
}
} else if ("advertiser".equalsIgnoreCase(entry.getKey())) {
final String advertiserString =
getSubst().replace(entry.getValue());
- if (advertiserString != null) {
- advertiser = (Advertiser)
Class.forName(advertiserString).newInstance();
+ if (advertiserString != null)
+ {
+ final PluginType type =
getPluginManager().getPluginType(advertiserString);
+ if (type != null)
+ {
+ final Class<Advertiser> clazz =
type.getPluginClass();
+ advertiser = clazz.newInstance();
+ }
}
}
}
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=1456325&r1=1456324&r2=1456325&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
Thu Mar 14 05:14:38 2013
@@ -142,15 +142,19 @@ public class XMLConfiguration extends Ba
}
} else if ("advertiser".equalsIgnoreCase(entry.getKey())) {
final String advertiserString =
getSubst().replace(entry.getValue());
- if (advertiserString != null) {
- try {
- advertiser = (Advertiser)
Class.forName(advertiserString).newInstance();
- } catch (InstantiationException e) {
- System.err.println("InstantiationException
attempting to instantiate advertiser: " + advertiserString);
- } catch (IllegalAccessException e) {
- System.err.println("IllegalAccessException
attempting to instantiate advertiser: " + advertiserString);
- } catch (ClassNotFoundException e) {
- System.err.println("ClassNotFoundException
attempting to instantiate advertiser: " + advertiserString);
+ if (advertiserString != null)
+ {
+ final PluginType type =
getPluginManager().getPluginType(advertiserString);
+ if (type != null)
+ {
+ final Class<Advertiser> clazz =
type.getPluginClass();
+ try {
+ advertiser = clazz.newInstance();
+ } catch (InstantiationException e) {
+ System.err.println("InstantiationException
attempting to instantiate advertiser: " + advertiserString);
+ } catch (IllegalAccessException e) {
+ System.err.println("IllegalAccessException
attempting to instantiate advertiser: " + advertiserString);
+ }
}
}
}
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java?rev=1456325&r1=1456324&r2=1456325&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java
(original)
+++
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java
Thu Mar 14 05:14:38 2013
@@ -22,12 +22,14 @@ import java.lang.reflect.Method;
import java.util.Hashtable;
import java.util.Map;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.status.StatusLogger;
/**
* Advertise an entity via ZeroConf/MulticastDNS and the JmDNS library.
*
*/
+@Plugin(name = "multicastdns", type = "Core", elementType = "advertiser",
printObject = false)
public class MulticastDNSAdvertiser implements Advertiser {
protected static final Logger LOGGER = StatusLogger.getLogger();
private static Object jmDNS = initializeJMDNS();
Modified:
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java?rev=1456325&r1=1456324&r2=1456325&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java
(original)
+++
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java
Thu Mar 14 05:14:38 2013
@@ -16,11 +16,13 @@
*/
package org.apache.logging.log4j.core.config;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.net.Advertiser;
import java.util.HashMap;
import java.util.Map;
+@Plugin(name = "memory", type = "Core", elementType = "advertiser",
printObject = false)
public class InMemoryAdvertiser implements Advertiser {
private static Map<Object, Map<String, String>> properties = new
HashMap<Object, Map<String, String>>();
Modified:
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-advertiser.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-advertiser.xml?rev=1456325&r1=1456324&r2=1456325&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-advertiser.xml
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-advertiser.xml Thu
Mar 14 05:14:38 2013
@@ -16,8 +16,8 @@
limitations under the License.
-->
-<configuration status="debug" dest="target/status.log" name="XMLConfigTest"
packages="org.apache.logging.log4j.test"
-
advertiser="org.apache.logging.log4j.core.config.InMemoryAdvertiser">
+<configuration status="debug" dest="target/status.log" name="XMLConfigTest"
packages="org.apache.logging.log4j.core,org.apache.logging.log4j.test"
+ advertiser="memory">
<ThresholdFilter level="debug"/>
<appenders>