logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r365312 - in /logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw: ChainsawAppenderHandler.java LogUI.java help/Tutorial.java receivers/ReceiversPanel.java receivers/ReceiversTreeModel.java
Date Mon, 02 Jan 2006 08:05:08 GMT
Author: carnold
Date: Mon Jan  2 00:05:04 2006
New Revision: 365312

URL: http://svn.apache.org/viewcvs?rev=365312&view=rev
Log:
Bug 35452: Chainsaw fixes for LoggerRepository work

Modified:
    logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java
    logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogUI.java
    logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/help/Tutorial.java
    logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
    logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversTreeModel.java

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java?rev=365312&r1=365311&r2=365312&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java
(original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java
Mon Jan  2 00:05:04 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
 import org.apache.log4j.rule.ExpressionRule;
 import org.apache.log4j.rule.Rule;
 import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.LoggerRepositoryEx;
 import org.apache.log4j.spi.LoggingEventFieldResolver;
 
 /**
@@ -145,7 +146,7 @@
     });
     LogManager.getRootLogger().addAppender(handler);
     SocketReceiver receiver = new SocketReceiver(4445);
-    LogManager.getLoggerRepository().getPluginRegistry().addPlugin(receiver);
+    ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPlugin(receiver);
     receiver.activateOptions();
     Thread.sleep(60000);
   }

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogUI.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogUI.java?rev=365312&r1=365311&r2=365312&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogUI.java (original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/LogUI.java Mon Jan  2 00:05:04
2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -114,6 +114,8 @@
 import org.apache.log4j.rule.Rule;
 import org.apache.log4j.spi.Decoder;
 import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.LoggerRepositoryEx;
 import org.apache.log4j.xml.XMLDecoder;
 
 
@@ -308,8 +310,12 @@
     //configuration initialized here
     logUI.ensureChainsawAppenderHandlerAdded();
     logger = LogManager.getLogger(LogUI.class);
-    logger.getLoggerRepository().setProperty(Constants.APPLICATION_KEY,"log");
-    logger.getLoggerRepository().setProperty(Constants.HOSTNAME_KEY,"chainsaw");
+    LoggerRepository repo = logger.getLoggerRepository();
+    if (repo instanceof LoggerRepositoryEx) {
+        LoggerRepositoryEx repox = (LoggerRepositoryEx) repo;
+        repox.setProperty(Constants.APPLICATION_KEY,"log");
+        repox.setProperty(Constants.HOSTNAME_KEY,"chainsaw");
+    }
     
     String config = model.getConfigurationURL();
     if(config!=null && (!(config.trim().equals("")))) {
@@ -595,7 +601,10 @@
    * table columns, and sets itself viewable.
    */
   public void activateViewer() {
-    this.pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();  
+    LoggerRepository repo = LogManager.getLoggerRepository();
+    if (repo instanceof LoggerRepositoryEx) {
+        this.pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry();
+    }  
     initGUI();
 
     initPrefModelListeners();
@@ -924,13 +933,16 @@
             new Thread(
               new Runnable() {
                 public void run() {
-                  PluginRegistry pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();
-                  List list = pluginRegistry.getPlugins(Generator.class);
-
-                  for (Iterator iter = list.iterator(); iter.hasNext();) {
-                    Plugin plugin = (Plugin) iter.next();
-                    pluginRegistry.stopPlugin(plugin.getName());
-                  }
+                  LoggerRepository repo = LogManager.getLoggerRepository();
+                  if (repo instanceof LoggerRepositoryEx) {
+                      PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry();
+                      List list = pluginRegistry.getPlugins(Generator.class);
+
+                      for (Iterator iter = list.iterator(); iter.hasNext();) {
+                         Plugin plugin = (Plugin) iter.next();
+                         pluginRegistry.stopPlugin(plugin.getName());
+                      }
+                   }
                 }
               }).start();
             setEnabled(false);

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/help/Tutorial.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/help/Tutorial.java?rev=365312&r1=365311&r2=365312&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/help/Tutorial.java (original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/help/Tutorial.java Mon Jan 
2 00:05:04 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@
 import org.apache.log4j.chainsaw.Generator;
 import org.apache.log4j.plugins.Plugin;
 import org.apache.log4j.plugins.PluginRegistry;
-
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.LoggerRepositoryEx;
 
 /**
  * A runnable element that installs into the Log4j environment some fake Receivers
@@ -37,13 +38,16 @@
       Plugin p2 = new Generator("Generator 2");
       Plugin p3 = new Generator("Generator 3");
       
-      PluginRegistry pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();
-      pluginRegistry.addPlugin(p1);
-      p1.activateOptions();
-      pluginRegistry.addPlugin(p2);
-      p2.activateOptions();
-      pluginRegistry.addPlugin(p3);
-      p3.activateOptions();
+      LoggerRepository repo = LogManager.getLoggerRepository();
+      if (repo instanceof LoggerRepositoryEx) {
+      	PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry();
+        pluginRegistry.addPlugin(p1);
+        p1.activateOptions();
+        pluginRegistry.addPlugin(p2);
+        p2.activateOptions();
+        pluginRegistry.addPlugin(p3);
+        p3.activateOptions();
+      }
       
   }
 }

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java?rev=365312&r1=365311&r2=365312&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
(original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
Mon Jan  2 00:05:04 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -70,6 +70,8 @@
 import org.apache.log4j.chainsaw.messages.MessageCenter;
 import org.apache.log4j.net.SocketNodeEventListener;
 import org.apache.log4j.net.SocketReceiver;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.LoggerRepositoryEx;
 import org.apache.log4j.plugins.Pauseable;
 import org.apache.log4j.plugins.Plugin;
 import org.apache.log4j.plugins.PluginRegistry;
@@ -106,10 +108,15 @@
 
   public ReceiversPanel() {
     super(new BorderLayout());
-    pluginRegistry = LogManager.getLoggerRepository().getPluginRegistry();
+    LoggerRepository repo = LogManager.getLoggerRepository();
     final ReceiversTreeModel model = new ReceiversTreeModel();
+    if (repo instanceof LoggerRepositoryEx) {
+       pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry();
+       pluginRegistry.addPluginListener(model);
+    } else {
+       pluginRegistry = null;
+    }
     
-    pluginRegistry.addPluginListener(model);
     receiversTree.setModel(model);
 
     receiversTree.setExpandsSelectedPaths(true);
@@ -362,13 +369,15 @@
     /**
      * add this listener to all SocketReceivers
      */
-    List socketReceivers =
-      pluginRegistry.getPlugins(SocketReceiver.class);
-
-    for (Iterator iter = socketReceivers.iterator(); iter.hasNext();) {
-      SocketReceiver element = (SocketReceiver) iter.next();
-      element.addSocketNodeEventListener(listener);
-    }
+    if (pluginRegistry == null) {
+    	List socketReceivers =
+      		pluginRegistry.getPlugins(SocketReceiver.class);
+
+    	for (Iterator iter = socketReceivers.iterator(); iter.hasNext();) {
+      		SocketReceiver element = (SocketReceiver) iter.next();
+      		element.addSocketNodeEventListener(listener);
+    	}
+     }
   }
 
   protected ReceiversTreeModel getReceiverTreeModel() {

Modified: logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversTreeModel.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversTreeModel.java?rev=365312&r1=365311&r2=365312&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversTreeModel.java
(original)
+++ logging/chainsaw/trunk/src/java/org/apache/log4j/chainsaw/receivers/ReceiversTreeModel.java
Mon Jan  2 00:05:04 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.util.Collection;
+import java.util.Vector;
 import java.util.Enumeration;
 import java.util.Iterator;
 
@@ -29,6 +30,8 @@
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.net.SocketReceiver;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.LoggerRepositoryEx;
 import org.apache.log4j.plugins.Plugin;
 import org.apache.log4j.plugins.PluginEvent;
 import org.apache.log4j.plugins.PluginListener;
@@ -64,7 +67,13 @@
   public final synchronized ReceiversTreeModel refresh() {
     RootNode.removeAllChildren();
 
-    Collection receivers = LogManager.getLoggerRepository().getPluginRegistry().getPlugins(Receiver.class);
+    LoggerRepository repo = LogManager.getLoggerRepository();
+    Collection receivers;
+    if (repo instanceof LoggerRepositoryEx) {
+        receivers = ((LoggerRepositoryEx) repo).getPluginRegistry().getPlugins(Receiver.class);
+    } else {
+        receivers = new Vector();
+    }
 
     updateRootDisplay();
 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message