Search in sources :

Example 1 with XMLFormatter

use of java.util.logging.XMLFormatter in project j2objc by google.

the class XMLFormatterTest method testInvalidParameter.

public void testInvalidParameter() {
    formatter.getTail(null);
    try {
        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);
}
Also used : LogRecord(java.util.logging.LogRecord) XMLFormatter(java.util.logging.XMLFormatter)

Example 2 with XMLFormatter

use of java.util.logging.XMLFormatter in project jdk8u_jdk by JetBrains.

the class XMLFormatterDate method main.

/**
     * Before the fix, JDK8 prints: {@code
     * <record>
     *   <date>3913-11-18T17:35:40</date>
     *   <millis>1384792540403</millis>
     *   <sequence>0</sequence>
     *   <level>INFO</level>
     *   <thread>1</thread>
     *   <message>test</message>
     * </record>
     * }
     * After the fix, it should print: {@code
     * <record>
     *   <date>2013-11-18T17:35:40</date>
     *   <millis>1384792696519</millis>
     *   <sequence>0</sequence>
     *   <level>INFO</level>
     *   <thread>1</thread>
     *   <message>test</message>
     * </record>
     * }
     * @param args the command line arguments
     */
public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    try {
        Locale.setDefault(Locale.ENGLISH);
        final GregorianCalendar cal1 = new GregorianCalendar();
        final int year1 = cal1.get(Calendar.YEAR);
        LogRecord record = new LogRecord(Level.INFO, "test");
        XMLFormatter formatter = new XMLFormatter();
        final String formatted = formatter.format(record);
        System.out.println(formatted);
        final GregorianCalendar cal2 = new GregorianCalendar();
        final int year2 = cal2.get(Calendar.YEAR);
        if (year2 < 1900) {
            throw new Error("Invalid system year: " + year2);
        }
        StringBuilder buf2 = new StringBuilder().append("<date>").append(year2).append("-");
        if (!formatted.contains(buf2.toString())) {
            StringBuilder buf1 = new StringBuilder().append("<date>").append(year1).append("-");
            if (formatted.contains(buf1) && year2 == year1 + 1 && cal2.get(Calendar.MONTH) == Calendar.JANUARY && cal2.get(Calendar.DAY_OF_MONTH) == 1) {
                // Oh! The year just switched in the midst of the test...
                System.out.println("Happy new year!");
            } else {
                throw new Error("Expected year " + year2 + " not found in log:\n" + formatted);
            }
        }
    } finally {
        Locale.setDefault(locale);
    }
}
Also used : Locale(java.util.Locale) LogRecord(java.util.logging.LogRecord) XMLFormatter(java.util.logging.XMLFormatter) GregorianCalendar(java.util.GregorianCalendar)

Example 3 with XMLFormatter

use of java.util.logging.XMLFormatter in project j2objc by google.

the class XMLFormatterTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    formatter = new XMLFormatter();
    handler = new MockHandler();
    lr = new LogRecord(Level.SEVERE, "pattern");
}
Also used : LogRecord(java.util.logging.LogRecord) XMLFormatter(java.util.logging.XMLFormatter)

Example 4 with XMLFormatter

use of java.util.logging.XMLFormatter in project robovm by robovm.

the class OldXMLFormatterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    formatter = new XMLFormatter();
    handler = new MockHandler();
    lr = new LogRecord(Level.SEVERE, "pattern");
}
Also used : LogRecord(java.util.logging.LogRecord) XMLFormatter(java.util.logging.XMLFormatter)

Aggregations

LogRecord (java.util.logging.LogRecord)4 XMLFormatter (java.util.logging.XMLFormatter)4 GregorianCalendar (java.util.GregorianCalendar)1 Locale (java.util.Locale)1