Package java.util.logging

Examples of java.util.logging.XMLFormatter


        for (int i = 0; i < 3; i++) {
            handler = new FileHandler();
            handler.publish(r);
            handler.close();
        }
        assertFileContent(HOMEPATH, "java0.log", new XMLFormatter(), null);
    }
View Full Code Here


public class getTail
  implements Testlet
{
  public void test(TestHarness h)
  {
    XMLFormatter formatter = new XMLFormatter();
    StreamHandler handler = new StreamHandler();

    // Check #1.
    h.check(formatter.getTail(handler),
            "</log>" + System.getProperty("line.separator"));

    /* Check #2.
     *
     * The behavior of passing null is not specified, but
     * we want to check that we do the same as Sun's reference
     * implementation.
     */
    try
      {
        formatter.getTail(null);
        h.check(true);
      }
    catch (Exception ex)
      {
        h.check(false);
View Full Code Here

public class formatMessage
  implements Testlet
{
  public void test(TestHarness h)
  {
    XMLFormatter formatter = new XMLFormatter();
    LogRecord rec;

    // Check #1.
    try
      {
        formatter.formatMessage(null);
        h.check(false);
      }
    catch (NullPointerException _)
      {
        h.check(true);
      }
    catch (Exception _)
      {
        h.check(false);
      }


    // Check #2.
    rec = new LogRecord(Level.INFO, "foobar");
   
    //Need to force the default time zone to UTC or else
    //the comparison uses system time zone and makes the tests
    //break.
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    rec.setMillis(1234567);
    rec.setSequenceNumber(42);
    rec.setThreadID(21);
    h.check(formatter.format(rec),
            EXPECTED_PREFIX
            + "  <thread>21</thread>\n"
            + "  <message>foobar</message>\n"
            + "</record>\n");


    // Check #3.
    rec.setSourceClassName(
      "FakeClass");
    rec.setSourceMethodName("test(fake)");
    h.check(formatter.format(rec),
            EXPECTED_PREFIX
            + "  <class>FakeClass</class>\n"
            + "  <method>test(fake)</method>\n"
            + "  <thread>21</thread>\n"
            + "  <message>foobar</message>\n"
            + "</record>\n");


    // Check #4.
    rec.setMessage("foobar {1}-{0}");
    rec.setParameters(new String[] { "peace", "love" });
    h.check(formatter.format(rec),
            EXPECTED_PREFIX
            + "  <class>FakeClass</class>\n"
            + "  <method>test(fake)</method>\n"
            + "  <thread>21</thread>\n"
            + "  <message>foobar love-peace</message>\n"
            + "</record>\n");


    // Check #5.
    rec.setThrown(new TestException("non-localized message"));
    rec.setMessage("mauve is a beautiful color");
    h.check(deleteFrames(formatter.format(rec)),
            EXPECTED_PREFIX
            + "  <class>FakeClass</class>\n"
            + "  <method>test(fake)</method>\n"
            + "  <thread>21</thread>\n"
            + "  <message>mauve is a beautiful color</message>\n"
            + "  <exception>\n"
            + "    <message>gnu.testlet.java.util.logging"
            + ".XMLFormatter.formatMessage$TestException: localized "
            + "message</message>\n"
            + "  </exception>\n"
            + "</record>\n");

    // Check #6.
    rec.setMessage("ENTRY {0}");
    rec.setParameters(new String[] { "foo.bar" });
    rec.setResourceBundleName(TestResourceBundle.class.getName());
    rec.setThrown(null);
    h.check(formatter.format(rec),
            EXPECTED_PREFIX
            + "  <class>FakeClass</class>\n"
            + "  <method>test(fake)</method>\n"
            + "  <thread>21</thread>\n"
            + "  <message>ENTRY foo.bar</message>\n"
View Full Code Here

  public void test(TestHarness h)
  {
    Formatter formatter;
    StreamHandler handler;

    formatter = new XMLFormatter();
    handler = new StreamHandler();

    // Check point "no encoding set".
    h.checkPoint("no encoding set");
    h.check(formatter.getHead(handler),
View Full Code Here

        for (int i = 0; i < 3; i++) {
            handler = new FileHandler();
            handler.publish(r);
            handler.close();
        }
        assertFileContent(HOMEPATH, "java0.log", new XMLFormatter());
    }
View Full Code Here

  LogRecord lr = null;

  protected void setUp() throws Exception {
    super.setUp();
    formatter = new XMLFormatter();
    handler = new MockHandler();
    lr = new LogRecord(Level.SEVERE, "pattern");
  }
View Full Code Here

      formatter.format(null);
      fail();
    } catch (NullPointerException e) {
    }

    formatter = new XMLFormatter();
    lr = new LogRecord(Level.SEVERE, null);
    String output = formatter.format(lr);
    // System.out.println(formatter.getHead(handler)+output+formatter.getTail(handler));
    assertTrue(output.indexOf("<message") > 0);
  }
View Full Code Here

                lvl = Level.SEVERE;
            handler.setLevel(lvl);

            Formatter fmt = new SimpleFormatter();
            if (getStringFieldValue(Item.applicationLogFormat).equals("XML"))
                fmt = new XMLFormatter();
            handler.setFormatter(fmt);
            return handler;
        } catch (Exception ex) {
            getLogger().log(Level.WARNING, null, ex);
        }       
View Full Code Here

  LogRecord lr = null;

  protected void setUp() throws Exception {
    super.setUp();
    formatter = new XMLFormatter();
    handler = new MockHandler();
    lr = new LogRecord(Level.SEVERE, "pattern");
  }
View Full Code Here

      formatter.format(null);
      fail();
    } catch (NullPointerException e) {
    }

    formatter = new XMLFormatter();
    lr = new LogRecord(Level.SEVERE, null);
    String output = formatter.format(lr);
    // System.out.println(formatter.getHead(handler)+output+formatter.getTail(handler));
    assertTrue(output.indexOf("<message") > 0);
    }
View Full Code Here

TOP

Related Classes of java.util.logging.XMLFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.