Stay organized with collections
Save and categorize content based on your preferences.
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.
Summary
Inherited methods |
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
Public constructors
Public methods
public String format (LogRecord record)
Format the given message to XML.
This method can be overridden in a subclass.
It is recommended to use the Formatter.formatMessage
convenience method to localize and format the message field.
Parameters |
record |
LogRecord : the log record to be formatted. |
Returns |
String |
a formatted log record |
getHead
public String getHead (Handler h)
Return the header string for a set of XML formatted records.
Parameters |
h |
Handler : The target handler (can be null) |
Returns |
String |
a valid XML string |
getTail
public String getTail (Handler h)
Return the tail string for a set of XML formatted records.
Parameters |
h |
Handler : The target handler (can be null) |
Returns |
String |
a valid XML string |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# XMLFormatter\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nXMLFormatter\n============\n\n\n`\npublic\n\n\nclass\nXMLFormatter\n`\n\n\n`\n\n\n`\n\n`\n\nextends `[Formatter](/reference/java/util/logging/Formatter)`\n\n\n`\n\n`\n\n\n`\n\n|---|---|--------------------------------|\n| [java.lang.Object](/reference/java/lang/Object) |||\n| ↳ | [java.util.logging.Formatter](/reference/java/util/logging/Formatter) ||\n| | ↳ | java.util.logging.XMLFormatter |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nFormat a LogRecord into a standard XML format.\n\n\nThe DTD specification is provided as Appendix A to the\nJava Logging APIs specification.\n\n\nThe XMLFormatter can be used with arbitrary character encodings,\nbut it is recommended that it normally be used with UTF-8. The\ncharacter encoding can be set on the output Handler.\n\nSummary\n-------\n\n| ### Public constructors ||\n|----------------------------------------------------------------------------------|---|\n| ` `[XMLFormatter](/reference/java/util/logging/XMLFormatter#XMLFormatter())`() ` |\n\n| ### Public methods ||\n|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` `[String](/reference/java/lang/String) | ` `[format](/reference/java/util/logging/XMLFormatter#format(java.util.logging.LogRecord))`(`[LogRecord](/reference/java/util/logging/LogRecord)` record) ` Format the given message to XML. |\n| ` `[String](/reference/java/lang/String) | ` `[getHead](/reference/java/util/logging/XMLFormatter#getHead(java.util.logging.Handler))`(`[Handler](/reference/java/util/logging/Handler)` h) ` Return the header string for a set of XML formatted records. |\n| ` `[String](/reference/java/lang/String) | ` `[getTail](/reference/java/util/logging/XMLFormatter#getTail(java.util.logging.Handler))`(`[Handler](/reference/java/util/logging/Handler)` h) ` Return the tail string for a set of XML formatted records. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[java.util.logging.Formatter](/reference/java/util/logging/Formatter)` ` |---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[String](/reference/java/lang/String) | ` `[format](/reference/java/util/logging/Formatter#format(java.util.logging.LogRecord))`(`[LogRecord](/reference/java/util/logging/LogRecord)` record) ` Format the given log record and return the formatted string. | | ` `[String](/reference/java/lang/String) | ` `[formatMessage](/reference/java/util/logging/Formatter#formatMessage(java.util.logging.LogRecord))`(`[LogRecord](/reference/java/util/logging/LogRecord)` record) ` Localize and format the message string from a log record. | | ` `[String](/reference/java/lang/String) | ` `[getHead](/reference/java/util/logging/Formatter#getHead(java.util.logging.Handler))`(`[Handler](/reference/java/util/logging/Handler)` h) ` Return the header string for a set of formatted records. | | ` `[String](/reference/java/lang/String) | ` `[getTail](/reference/java/util/logging/Formatter#getTail(java.util.logging.Handler))`(`[Handler](/reference/java/util/logging/Handler)` h) ` Return the tail string for a set of formatted records. | ||\n| From class ` `[java.lang.Object](/reference/java/lang/Object)` ` |---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](/reference/java/lang/Object) | ` `[clone](/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object. | | ` boolean` | ` `[equals](/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](/reference/java/lang/Object)` obj) ` Indicates whether some other object is \"equal to\" this one. | | ` void` | ` `[finalize](/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final `[Class](/reference/java/lang/Class)`\u003c?\u003e` | ` `[getClass](/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`. | | ` int` | ` `[hashCode](/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object. | | ` final void` | ` `[notify](/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` `[notifyAll](/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor. | | ` `[String](/reference/java/lang/String) | ` `[toString](/reference/java/lang/Object#toString())`() ` Returns a string representation of the object. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||\n\nPublic constructors\n-------------------\n\n### XMLFormatter\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic XMLFormatter ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic methods\n--------------\n\n### format\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic String format (LogRecord record)\n```\n\nFormat the given message to XML.\n\n\nThis method can be overridden in a subclass.\nIt is recommended to use the [Formatter.formatMessage](/reference/java/util/logging/Formatter#formatMessage(java.util.logging.LogRecord))\nconvenience method to localize and format the message field.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-----------------------------------------------------|\n| `record` | `LogRecord`: the log record to be formatted. \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------|-------------------------------|\n| [String](/reference/java/lang/String) | a formatted log record \u003cbr /\u003e |\n\n### getHead\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic String getHead (Handler h)\n```\n\nReturn the header string for a set of XML formatted records.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|----------------------------------------------------|\n| `h` | `Handler`: The target handler (can be null) \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------|---------------------------|\n| [String](/reference/java/lang/String) | a valid XML string \u003cbr /\u003e |\n\n### getTail\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic String getTail (Handler h)\n```\n\nReturn the tail string for a set of XML formatted records.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|----------------------------------------------------|\n| `h` | `Handler`: The target handler (can be null) \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------|---------------------------|\n| [String](/reference/java/lang/String) | a valid XML string \u003cbr /\u003e |"]]