Stay organized with collections
Save and categorize content based on your preferences.
abstract class Formatter
Known Direct Subclasses
SimpleFormatter |
Print a brief summary of the LogRecord in a human readable format.
|
XMLFormatter |
Format a LogRecord into a standard XML format.
|
|
A Formatter provides support for formatting LogRecords.
Typically each logging Handler will have a Formatter associated with it. The Formatter takes a LogRecord and converts it to a string.
Some formatters (such as the XMLFormatter) need to wrap head and tail strings around a set of formatted records. The getHeader and getTail methods can be used to obtain these strings.
Summary
Protected constructors |
Construct a new formatter.
|
Public methods |
abstract String! |
Format the given log record and return the formatted string.
|
open String! |
Localize and format the message string from a log record.
|
open String! |
Return the header string for a set of formatted records.
|
open String! |
Return the tail string for a set of formatted records.
|
Protected constructors
protected Formatter()
Construct a new formatter.
Public methods
abstract fun format(record: LogRecord!): String!
Format the given log record and return the formatted string.
The resulting formatted String will normally include a localized and formatted version of the LogRecord's message field. 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. |
Return |
String! |
the formatted log record |
open fun formatMessage(record: LogRecord!): String!
Localize and format the message string from a log record. This method is provided as a convenience for Formatter subclasses to use when they are performing formatting.
The message string is first localized to a format string using the record's ResourceBundle. (If there is no ResourceBundle, or if the message key is not found, then the key is used as the format string.) The format String uses java.text style formatting.
- If there are no parameters, no formatter is used.
- Otherwise, if the string contains "{0" then java.text.MessageFormat is used to format the string.
- Otherwise no formatting is performed.
Parameters |
record |
LogRecord!: the log record containing the raw message |
Return |
String! |
a localized and formatted message |
getHead
open fun getHead(h: Handler!): String!
Return the header string for a set of formatted records.
This base class returns an empty string, but this may be overridden by subclasses.
Parameters |
h |
Handler!: The target handler (can be null) |
getTail
open fun getTail(h: Handler!): String!
Return the tail string for a set of formatted records.
This base class returns an empty string, but this may be overridden by subclasses.
Parameters |
h |
Handler!: The target handler (can be null) |
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Formatter\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nFormatter\n=========\n\n```\nabstract class Formatter\n```\n\n|---|----------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [java.util.logging.Formatter](#) |\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [SimpleFormatter](/reference/kotlin/java/util/logging/SimpleFormatter), [XMLFormatter](/reference/kotlin/java/util/logging/XMLFormatter) |------------------------------------------------------------------------|----------------------------------------------------------------------| | [SimpleFormatter](/reference/kotlin/java/util/logging/SimpleFormatter) | Print a brief summary of the `LogRecord` in a human readable format. | | [XMLFormatter](/reference/kotlin/java/util/logging/XMLFormatter) | Format a LogRecord into a standard XML format. | |\n\nA Formatter provides support for formatting LogRecords.\n\nTypically each logging Handler will have a Formatter associated with it. The Formatter takes a LogRecord and converts it to a string.\n\nSome formatters (such as the XMLFormatter) need to wrap head and tail strings around a set of formatted records. The getHeader and getTail methods can be used to obtain these strings.\n\nSummary\n-------\n\n| Protected constructors ||\n|----------------------------------------------------------|---|\n| [Formatter](#Formatter())`()` Construct a new formatter. |\n\n| Public methods ||\n|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | [format](#format(java.util.logging.LogRecord))`(`record:` `[LogRecord](/reference/kotlin/java/util/logging/LogRecord)!`)` Format the given log record and return the formatted string. |\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | [formatMessage](#formatMessage(java.util.logging.LogRecord))`(`record:` `[LogRecord](/reference/kotlin/java/util/logging/LogRecord)!`)` Localize and format the message string from a log record. |\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | [getHead](#getHead(java.util.logging.Handler))`(`h:` `[Handler](/reference/kotlin/java/util/logging/Handler)!`)` Return the header string for a set of formatted records. |\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | [getTail](#getTail(java.util.logging.Handler))`(`h:` `[Handler](/reference/kotlin/java/util/logging/Handler)!`)` Return the tail string for a set of formatted records. |\n\nProtected constructors\n----------------------\n\n### Formatter\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected Formatter()\n```\n\nConstruct a new formatter.\n\nPublic methods\n--------------\n\n### format\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun format(record: LogRecord!): String!\n```\n\nFormat the given log record and return the formatted string.\n\nThe resulting formatted String will normally include a localized and formatted version of the LogRecord's message field. It is recommended to use the [Formatter.formatMessage](#formatMessage(java.util.logging.LogRecord)) convenience method to localize and format the message field.\n\n| Parameters ||\n|----------|----------------------------------------------------------------------------------------------|\n| `record` | [LogRecord](/reference/kotlin/java/util/logging/LogRecord)!: the log record to be formatted. |\n\n| Return ||\n|-----------------------------------------------------------------------------------|--------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | the formatted log record |\n\n### formatMessage\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun formatMessage(record: LogRecord!): String!\n```\n\nLocalize and format the message string from a log record. This method is provided as a convenience for Formatter subclasses to use when they are performing formatting.\n\nThe message string is first localized to a format string using the record's ResourceBundle. (If there is no ResourceBundle, or if the message key is not found, then the key is used as the format string.) The format String uses java.text style formatting.\n\n- If there are no parameters, no formatter is used.\n- Otherwise, if the string contains \"{0\" then java.text.MessageFormat is used to format the string.\n- Otherwise no formatting is performed.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------------------------------------|\n| `record` | [LogRecord](/reference/kotlin/java/util/logging/LogRecord)!: the log record containing the raw message |\n\n| Return ||\n|-----------------------------------------------------------------------------------|-----------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | a localized and formatted message |\n\n### getHead\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getHead(h: Handler!): String!\n```\n\nReturn the header string for a set of formatted records.\n\nThis base class returns an empty string, but this may be overridden by subclasses.\n\n| Parameters ||\n|-----|-------------------------------------------------------------------------------------------|\n| `h` | [Handler](/reference/kotlin/java/util/logging/Handler)!: The target handler (can be null) |\n\n| Return ||\n|-----------------------------------------------------------------------------------|---------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | header string |\n\n### getTail\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getTail(h: Handler!): String!\n```\n\nReturn the tail string for a set of formatted records.\n\nThis base class returns an empty string, but this may be overridden by subclasses.\n\n| Parameters ||\n|-----|-------------------------------------------------------------------------------------------|\n| `h` | [Handler](/reference/kotlin/java/util/logging/Handler)!: The target handler (can be null) |\n\n| Return ||\n|-----------------------------------------------------------------------------------|-------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | tail string |"]]