Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6266342

XMLFormatter log formatter does not show exception chain for thrown exceptions

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Future Project
    • Icon: P4 P4
    • None
    • 6
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      The XMLFormatter log formatter doesn't print cause exceptions of exceptions thrown in log records.

      This report was originally filed as Incident Review ID 323362, but contact with the engineer in charge of it stopped abruptly, so it must have been thrown out or lost somehow.

      I was asked in that report to provide a full test case. I have done so.

      JUSTIFICATION :
      Chained exceptions were added to Java in release 1.4.0. The log formatters should support them.

      ACTUAL -
      Here is the test case. It creates a file log-output.xml. You can see
      that there is no mention of the IllegalArgumentException in the log
      file, even though it was passed to the RuntimeException as the cause.

      import java.io.IOException;
      import java.util.logging.FileHandler;
      import java.util.logging.Handler;
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import java.util.logging.XMLFormatter;

      public class XMLFormatterDemo {
           public static void main(String[] args) {
               Logger l = Logger.getAnonymousLogger();
               l.setLevel(Level.ALL);

               Handler handler;
               try {
                   handler = new FileHandler("log-output.xml");
               } catch (IOException e) {
                   e.printStackTrace();
                   return;
               }
               handler.setFormatter(new XMLFormatter());
               l.addHandler(handler);

               // log an exception
               IllegalArgumentException cause = new
      IllegalArgumentException("bad argument");
               l.log(Level.SEVERE, "Exception", new RuntimeException("Some
      error", cause));
           }
      }

      ---------- END SOURCE ----------
      ###@###.### 2005-05-06 05:27:59 GMT

            Unassigned Unassigned
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: