Guys,

Attached is a patch (for the 'fop-0_20_2-maintain' branch) for 
MessageHandler which improves support for screen logging, and makes the 
command line tool, the Ant task and TestConverter make use of the fix.

The problem with MessageHandler is that it was obtaining it's Logkit 
Logger directly from Logkit using a static method. Obviously, this 
cannot be done anymore, hence I've added 
MessageHandler.setScreenLogger() to allow an application to set this. It 
isn't immediately obvious that MessageHandler.setScreenLogger() needs to 
get called, so I've updated the docs (embedding.xml) to cover these 
changes, a patch for which is also attached.

MessageHandler does print a warning if a logger has not been set the 
first time it MessageHandler.log() is called, but due to 
MessageHandler's design, it had to be done in a klugey manner. The only 
way to fix this is AFAICT is to refactor MessageHandler's design - so 
that it becomes a singleton object instead of a bunch of static methods 
and properties. I think this is a much better design pattern, but will 
be a bit of work, so I'll get it done if people think it is worthwhile.

Mike.

-- 
Michael Gratton <[EMAIL PROTECTED]>
Recall Design <http://www.recalldesign.com/>
s: 53 Gilbert Street Adelaide SA 5000 Australia
t: +61 8 8217 0500 f: +61 8 8217 0555
Index: src/org/apache/fop/messaging/MessageHandler.java
===================================================================
RCS file: 
/home/cvspublic/xml-fop/src/org/apache/fop/messaging/Attic/MessageHandler.java,v
retrieving revision 1.6.2.1
diff -u -r1.6.2.1 MessageHandler.java
--- src/org/apache/fop/messaging/MessageHandler.java    17 Mar 2002 23:37:07 -0000     
 1.6.2.1
+++ src/org/apache/fop/messaging/MessageHandler.java    19 Mar 2002 03:59:35 -0000
@@ -48,6 +48,7 @@
     public static final int EVENT = 2;
     public static final int NONE = 3;    // this should always be the last method
 
+    private static Logger logger = null;
     private static String logfileName = "fop.log";
     private static PrintWriter writer;
     private static int outputMethod = SCREEN;
@@ -81,18 +82,19 @@
         }
     }
 
-    // temp workaround
-    private static Logger logger = null;
+    
 
     /**
      * informs the user of the message
      * @param message the message for the user
      */
     public static void log(String message) {
+       if (logger == null) {
+           logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
+           logger.warn("Screen logger not set.");
+       }
+
         if (!quiet) {
-            if(logger == null) {
-                logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
-            }
             setMessage(message);
             switch (outputMethod) {
             case SCREEN:
@@ -138,9 +140,6 @@
      */
 
     public static void error(String errorMessage) {
-        if(logger == null) {
-            logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
-        }
         setMessage(errorMessage);
         switch (outputMethod) {
         case SCREEN:
@@ -195,6 +194,16 @@
      */
     public static void removeListener(MessageListener listener) {
         listeners.removeElement(listener);
+    }
+
+    /**
+     * Sets the Logger used for the screen output method.
+     * @param newLogger a logger for screen output. This may not be null.
+     */
+    public static void setScreenLogger(Logger newLogger) {
+       if (newLogger == null)
+           throw new NullPointerException();
+       logger = newLogger;
     }
 
     /**
Index: src/org/apache/fop/apps/CommandLineOptions.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/apps/CommandLineOptions.java,v
retrieving revision 1.14.2.1
diff -u -r1.14.2.1 CommandLineOptions.java
--- src/org/apache/fop/apps/CommandLineOptions.java     17 Mar 2002 23:37:06 -0000     
 1.14.2.1
+++ src/org/apache/fop/apps/CommandLineOptions.java     19 Mar 2002 03:59:36 -0000
@@ -15,6 +15,7 @@
 // FOP
 import org.apache.fop.configuration.Configuration;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.messaging.MessageHandler;
 
 // Avalon
 import org.apache.avalon.framework.logger.ConsoleLogger;
@@ -92,7 +93,7 @@
     public CommandLineOptions(String[] args)
             throws FOPException, FileNotFoundException {
 
-        log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
+        setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
 
         boolean optionsParsed = true;
         rendererOptions = new java.util.Hashtable();
@@ -123,13 +124,13 @@
         for (int i = 0; i < args.length; i++) {
             if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
                 errorDump = new Boolean(true);
-                log = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
+                setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG));
             } else if (args[i].equals("-x")
                        || args[i].equals("--dump-config")) {
                 dumpConfiguration = new Boolean(true);
             } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
                 quiet = new Boolean(true);
-                log = new ConsoleLogger(ConsoleLogger.LEVEL_ERROR);
+                setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_ERROR));
             } else if (args[i].equals("-c")) {
                 if ((i + 1 == args.length)
                         || (args[i + 1].charAt(0) == '-')) {
@@ -346,6 +347,11 @@
 
         }
     }    // end checkSettings
+
+    private void setLogger(Logger newLogger) {
+       this.log = newLogger;
+       MessageHandler.setScreenLogger(newLogger);
+    }
 
     /**
      * returns the chosen renderer, throws FOPException
Index: src/org/apache/fop/tools/TestConverter.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/tools/TestConverter.java,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 TestConverter.java
--- src/org/apache/fop/tools/TestConverter.java 17 Mar 2002 23:37:08 -0000      
1.15.2.1
+++ src/org/apache/fop/tools/TestConverter.java 19 Mar 2002 03:59:36 -0000
@@ -9,6 +9,7 @@
 
 import org.apache.fop.apps.*;
 import org.apache.fop.configuration.*;
+import org.apache.fop.messaging.MessageHandler;
 
 import org.apache.avalon.framework.logger.ConsoleLogger;
 import org.apache.avalon.framework.logger.Logger;
@@ -87,6 +88,7 @@
 
     private void setupLogging() {
        log = new ConsoleLogger(ConsoleLogger.LEVEL_ERROR);
+       MessageHandler.setScreenLogger(log);    
     }
 
     public void setOutputPDF(boolean pdf) {
Index: src/org/apache/fop/tools/anttasks/Fop.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/tools/anttasks/Fop.java,v
retrieving revision 1.14.2.1
diff -u -r1.14.2.1 Fop.java
--- src/org/apache/fop/tools/anttasks/Fop.java  17 Mar 2002 23:37:08 -0000      
1.14.2.1
+++ src/org/apache/fop/tools/anttasks/Fop.java  19 Mar 2002 03:59:36 -0000
@@ -195,6 +195,7 @@
         this.task = task;
 
        log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
+       MessageHandler.setScreenLogger(log);
     }
 
     private int determineRenderer(String format) {
Index: docs/xml-docs/fop/embedding.xml
===================================================================
RCS file: /home/cvspublic/xml-fop/docs/xml-docs/fop/embedding.xml,v
retrieving revision 1.11.2.2
diff -u -r1.11.2.2 embedding.xml
--- docs/xml-docs/fop/embedding.xml     2 Mar 2002 17:40:26 -0000       1.11.2.2
+++ docs/xml-docs/fop/embedding.xml     19 Mar 2002 03:58:00 -0000
@@ -37,22 +37,17 @@
    driver.setRenderer(RENDER_PDF);
    driver.run();]]></source>
 
-  <p>You also need to set the Logger for logging messages, see
-     <jump href="http://jakarta.apache.org/avalon/logkit/index.html";>Jakarta 
Logkit</jump>
-     for more information.
+  <p>You also need to set up logging. Global logging for all FOP
+    processes is managed by MessageHandler. Per-instance logging
+    is handled by Driver. You want to set both using an implementation
+    of org.apache.avalon.framework.logger.Logger. See
+    <jump href="http://jakarta.apache.org/avalon/framework/";>Jakarta
+    Avalon Framework</jump> for more information.
   </p>
     <source><![CDATA[
-    Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
-    PatternFormatter formatter = new PatternFormatter(
-       "[%{priority}]: %{message}\n%{throwable}" );
-
-    LogTarget target = null;
-    target = new StreamTarget(System.out, formatter);
-
-    hierarchy.setDefaultLogTarget(target);
-    log = hierarchy.getLoggerFor("fop");
-    log.setPriority(Priority.INFO);
-    driver.setLogger(log);]]></source>
+    Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
+    MessageHandler.setScreenLogger(logger);
+    driver.setLogger(logger);]]></source>
 
   <p>To setup the user config file you can do the following
   </p>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to