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 Specification
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 (using
LogRecord.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 using
Instant.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.
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.
| Modifier and Type | Field and Description |
|---|---|
| private final LogManager | |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private void | |
| public String | Returns: a formatted log recordthe log record to be formatted. record)Implements abstract java. Format the given message to XML. |
| public String | Returns: a valid XML stringThe target handler (can be null) h)Overrides java. Return the header string for a set of XML formatted records. |
| public String | Returns: a valid XML stringThe target handler (can be null) h)Overrides java. Return the tail string for a set of XML formatted records. |
| manager | back to summary |
|---|---|
| private final LogManager manager | |
| useInstant | back to summary |
|---|---|
| private final boolean useInstant | |
| XMLFormatter | back to summary |
|---|---|
| public XMLFormatter() Creates a new instance of XMLFormatter. Implementation Specification Since JDK 9, the XMLFormatter will print out the record event time as an Instant. This instant
has the best resolution available on the system. The
This new behavior can be turned off, and the old formatting restored,
by specifying a property in the logging configuration.
If | |
| a2 | back to summary |
|---|---|
| private void a2(StringBuilder sb, int x) | |
| appendISO8601 | back to summary |
|---|---|
| private void appendISO8601(StringBuilder sb, long millis) | |
| escape | back to summary |
|---|---|
| private void escape(StringBuilder sb, String text) | |
| format | back to summary |
|---|---|
| public String format(LogRecord record) Implements abstract java. Format the given message to XML.
This method can be overridden in a subclass.
It is recommended to use the | |
| getHead | back to summary |
|---|---|
| public String getHead(Handler h) Overrides java. Return the header string for a set of XML formatted records. | |
| getTail | back to summary |
|---|---|
| public String getTail(Handler h) Overrides java. Return the tail string for a set of XML formatted records. | |