XMLFormatter (Java SE 9 & JDK 9 ) (original) (raw)

public class XMLFormatter
extends Formatter
Format a LogRecord into a standard XML format.
The DTD specification is provided as Appendix A to the Java Logging APIs specification.
The XMLFormatter can be used with arbitrary character encodings, but it is recommended that it normally be used with UTF-8. The character encoding can be set on the output Handler.
Implementation Requirements:
Since JDK 9, instances of LogRecord contain an Instant which can have nanoseconds below the millisecond resolution. The DTD specification has been updated to allow for an optional<nanos> element. By default, the XMLFormatter will compute the nanosecond adjustment below the millisecond resolution (usingLogRecord.getInstant().getNano() % 1000_000) - and if this is not 0, this adjustment value will be printed in the new <nanos> element. The event instant can then be reconstructed usingInstant.ofEpochSecond(millis/1000L, (millis % 1000L) * 1000_000L + nanos) where millis and nanos represent the numbers serialized in the <millis> and <nanos> elements, respectively.
The <date> element will now contain the whole instant as formatted by the DateTimeFormatter.ISO_INSTANT formatter.
For compatibility with old parsers, XMLFormatters can be configured to revert to the old format by specifying a<xml-formatter-fully-qualified-class-name>.useInstant = false property in the logging configuration. When useInstant is false, the old formatting will be preserved. When useInstant is true (the default), the <nanos> element will be printed and the<date> element will contain the formatted instant.
For instance, in order to configure plain instances of XMLFormatter to omit the new <nano> element,java.util.logging.XMLFormatter.useInstant = false can be specified in the logging configuration.
Since:
1.4

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2017, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.