logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r1480877 - in /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config: JSONConfiguration.java XMLConfiguration.java
Date Fri, 10 May 2013 04:43:46 GMT
Author: sdeboy
Date: Fri May 10 04:43:46 2013
New Revision: 1480877

URL: http://svn.apache.org/r1480877
Log:
Expose the XML or JSON configuration text via the Advertiser mechanism.

content: the configuration text
contentType: text/xml or application/json
name: configuration

Advertised during configuration.start, unadvertised during configuration.stop if the Advertiser
is set


Modified:
    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

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=1480877&r1=1480876&r2=1480877&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
Fri May 10 04:43:46 2013
@@ -41,6 +41,7 @@ import java.io.PrintStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -56,6 +57,10 @@ public class JSONConfiguration extends B
 
     private final List<Status> status = new ArrayList<Status>();
 
+    private Map<String, String> advertisedConfiguration;
+    
+    private Object advertisement;
+
     private JsonNode root;
 
     private final List<String> messages = new ArrayList<String>();
@@ -126,6 +131,10 @@ public class JSONConfiguration extends B
                         {
                             final Class<Advertiser> clazz = type.getPluginClass();
                             advertiser = clazz.newInstance();
+                            advertisedConfiguration = new HashMap<String, String>();
+                            advertisedConfiguration.put("content", new String(buffer));
+                            advertisedConfiguration.put("contentType", "application/json");
+                            advertisedConfiguration.put("name", "configuration");
                         }
                     }
                 }
@@ -162,7 +171,16 @@ public class JSONConfiguration extends B
         }
     }
 
-     @Override
+    @Override
+    public void stop() {
+        super.stop();
+        if (advertiser != null && advertisement != null)
+        {
+            advertiser.unadvertise(advertisement);
+        }
+    }
+
+    @Override
     public void setup() {
         final Iterator<Map.Entry<String, JsonNode>> iter = root.getFields();
         final List<Node> children = rootNode.getChildren();
@@ -183,6 +201,10 @@ public class JSONConfiguration extends B
             }
             return;
         }
+        if (advertiser != null && advertisedConfiguration != null)
+        {
+            advertisement = advertiser.advertise(advertisedConfiguration);
+        }
     }
 
     public Configuration reconfigure() {

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=1480877&r1=1480876&r2=1480877&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
Fri May 10 04:43:46 2013
@@ -55,6 +55,7 @@ import java.io.PrintStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -72,6 +73,10 @@ public class XMLConfiguration extends Ba
 
     private final List<Status> status = new ArrayList<Status>();
 
+    private Map<String, String> advertisedConfiguration;
+
+    private Object advertisement;
+
     private Element rootElement;
 
     private boolean strict;
@@ -151,6 +156,10 @@ public class XMLConfiguration extends Ba
                             final Class<Advertiser> clazz = type.getPluginClass();
                             try {
                                 advertiser = clazz.newInstance();
+                                advertisedConfiguration = new HashMap<String, String>();
+                                advertisedConfiguration.put("content", new String(buffer));
+                                advertisedConfiguration.put("contentType", "text/xml");
+                                advertisedConfiguration.put("name", "configuration");
                             } catch (InstantiationException e) {
                                 System.err.println("InstantiationException attempting to
instantiate advertiser: " + advertiserString);
                             } catch (IllegalAccessException e) {
@@ -225,6 +234,15 @@ public class XMLConfiguration extends Ba
     }
 
     @Override
+    public void stop() {
+        super.stop();
+        if (advertiser != null && advertisement != null)
+        {
+            advertiser.unadvertise(advertisement);
+        }
+    }
+
+    @Override
     public void setup() {
         if (rootElement == null) {
             LOGGER.error("No logging configuration");
@@ -238,6 +256,10 @@ public class XMLConfiguration extends Ba
             return;
         }
         rootElement = null;
+        if (advertiser != null && advertisedConfiguration != null)
+        {
+            advertisement = advertiser.advertise(advertisedConfiguration);
+        }
     }
 
     public Configuration reconfigure() {



Mime
View raw message