Here is a patch that moves the creation of the Main Chainsaw window from the
Start class to the ChainsawAppender class.  It gets created in the
activateOptions() method of the ChainsawAppender class.  I wanted to float
this patch before applying it in cvs.

- This is very much like the way LF5 works today, if I remember correctly.
- Eventually I think we should allow multiple instances of ChainsawAppender,
each with its own table model and its own instance of Main (or tab panel, in
the future?) created via a Main(TableModel) constructor.  This will allow
one to configure specific loggers to output to specific ChainsawAppenders
and thus specific Main windows, all in the configuration file.  This is a
step in that direction.
- I modified the Start code so that if no configuration file is found, a
default ChainsawAppender is created, attached to the root logger, and
activated.  This allows Chainsaw to still be used as a reader for offline
xml files.

Some next steps:

- I think that the Main class is now misnamed.  I think it should become
MainWindow or MainGUI.  Something more descriptive to what it is being used
for.  We will still need to keep a deprecated version of Main around (that
uses Start like today), but all the gui functionality gets moved to the new
class.

- You'll notice that in the case where no configuration file is specified I
set the level of the "org.apache.log4j.chainsaw" logger to info.  This is to
avoid continuous output of debug statements by Chainsaw into the Chainsaw
appender and window.  If you look at Paul's config file, you'll see he sets
the level to info as well.  I know that Ceki did not like my idea that
Chainsaw specific log events should be not be logged to the default
repository but instead to a Chainsaw specific Repository, but something
needs to be done.  I feel that Chainsaw specific messages should not be
mixed with the messages being received from remote sources.  Why would I
want that?  Why should I need to worry about configuring a level setting for
the chainsaw logger in my configuration so that I don't see those messages?
If the Chainsaw code was instrumented to get its loggers from a Chainsaw
specific Hierarchy, then the messages could be routed and viewed outside of
the messages being received remotely.  And the user would never need to know
about it.  Unless they wanted to, of course.  We could allow some
configuration of that hierarchy in case just sending them to the
ConsoleAppender is not good enough. (I could see us providing a singleton
window to view them if needed).

Let me know what you think.  Paul, I still need to look at the race
condition you mentioned previously; I haven't had a chance yet.

-Mark


Index: Start.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/Start.java,v
retrieving revision 1.3
diff -u -r1.3 Start.java
--- Start.java  11 Mar 2003 04:18:34 -0000      1.3
+++ Start.java  12 Mar 2003 06:49:27 -0000
@@ -49,6 +49,8 @@

 package org.apache.log4j.chainsaw;

+import org.apache.log4j.LogManager;
+import org.apache.log4j.Level;
 import org.apache.log4j.xml.DOMConfigurator;

 import java.io.File;
@@ -74,14 +76,23 @@

   public static void main(String[] args) {
     initLog4J();
-    new Main();
   }

   private static void initLog4J() {
     /** initialise log4j **/
     final FinderStrategies strategies = new FinderStrategies();
     final URL url = strategies.findConfiguration();
-    DOMConfigurator.configure(url);
+
+    // if a configuration file is specified, use it.
+    if (url != null) {
+      DOMConfigurator.configure(url);
+    // else no configuration specified, create an instance to use
+    } else {
+
LogManager.getLogger("org.apache.log4j.chainsaw").setLevel(Level.INFO);
+      ChainsawAppender appender = new ChainsawAppender();
+      LogManager.getRootLogger().addAppender(appender);
+      appender.activateOptions();
+    }
   }

   private static class FinderStrategies implements Log4JConfigurationFinder
{
@@ -106,8 +117,7 @@
         }
       }

-      throw new RuntimeException(
-        "Failed to locate a Log4J configuration" + " via any means");
+      return null;
     }
   }

Index: ChainsawAppender.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawAppender.
java,v
retrieving revision 1.2
diff -u -r1.2 ChainsawAppender.java
--- ChainsawAppender.java       11 Mar 2003 03:56:57 -0000      1.2
+++ ChainsawAppender.java       12 Mar 2003 06:49:28 -0000
@@ -138,6 +138,13 @@
   }

   /**
+   * Activates and instance of the Chainsaw gui window
+   */
+  public void activateOptions() {
+    new Main();
+  }
+
+  /**
    * Close does nothing
    */
   public void close() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to