# Formatter

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Protected Ctors](https://developer.android.com/reference/java/util/logging/Formatter#proctors)\|[Methods](https://developer.android.com/reference/java/util/logging/Formatter#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/logging/Formatter#inhmethods)  

# Formatter

`
public


abstract
class
Formatter
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.logging.Formatter |

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known direct subclasses [SimpleFormatter](https://developer.android.com/reference/java/util/logging/SimpleFormatter),[XMLFormatter](https://developer.android.com/reference/java/util/logging/XMLFormatter) |----------------------------------------------------------------------------------------------|--------------------------------------------------------------------| | [SimpleFormatter](https://developer.android.com/reference/java/util/logging/SimpleFormatter) | Print a brief summary of the`LogRecord`in a human readable format. | | [XMLFormatter](https://developer.android.com/reference/java/util/logging/XMLFormatter)       | Format a LogRecord into a standard XML format.                     | |

<br />

*** ** * ** ***

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                                                     ||
|---------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Formatter](https://developer.android.com/reference/java/util/logging/Formatter#Formatter())`() ` Construct a new formatter. |

|                                                                                                                                                                             ### Public methods                                                                                                                                                                             ||
|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[String](https://developer.android.com/reference/java/lang/String) | ` `[format](https://developer.android.com/reference/java/util/logging/Formatter#format(java.util.logging.LogRecord))`(`[LogRecord](https://developer.android.com/reference/java/util/logging/LogRecord)` record) ` Format the given log record and return the formatted string.            |
| ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[formatMessage](https://developer.android.com/reference/java/util/logging/Formatter#formatMessage(java.util.logging.LogRecord))`(`[LogRecord](https://developer.android.com/reference/java/util/logging/LogRecord)` record) ` Localize and format the message string from a log record. |
| ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[getHead](https://developer.android.com/reference/java/util/logging/Formatter#getHead(java.util.logging.Handler))`(`[Handler](https://developer.android.com/reference/java/util/logging/Handler)` h) ` Return the header string for a set of formatted records.                         |
| ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[getTail](https://developer.android.com/reference/java/util/logging/Formatter#getTail(java.util.logging.Handler))`(`[Handler](https://developer.android.com/reference/java/util/logging/Handler)` h) ` Return the tail string for a set of formatted records.                           |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/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](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/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](https://developer.android.com/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](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Protected constructors

### Formatter

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected Formatter ()
```

Construct a new formatter.

<br />

## Public methods

### format

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract String format (LogRecord record)
```

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](https://developer.android.com/reference/java/util/logging/Formatter#formatMessage(java.util.logging.LogRecord))convenience method to localize and format the message field.

<br />

|                          Parameters                           ||
|----------|-----------------------------------------------------|
| `record` | `LogRecord`: the log record to be formatted. <br /> |

|                                               Returns                                               ||
|--------------------------------------------------------------------|---------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the formatted log record <br /> |

### formatMessage

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String formatMessage (LogRecord record)
```

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.

<br />

<br />

|                               Parameters                                ||
|----------|---------------------------------------------------------------|
| `record` | `LogRecord`: the log record containing the raw message <br /> |

|                                                   Returns                                                    ||
|--------------------------------------------------------------------|------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a localized and formatted message <br /> |

### getHead

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getHead (Handler h)
```

Return the header string for a set of formatted records.

This base class returns an empty string, but this may be overridden by subclasses.

<br />

|                       Parameters                        ||
|-----|----------------------------------------------------|
| `h` | `Handler`: The target handler (can be null) <br /> |

|                                         Returns                                          ||
|--------------------------------------------------------------------|----------------------|
| [String](https://developer.android.com/reference/java/lang/String) | header string <br /> |

### getTail

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getTail (Handler h)
```

Return the tail string for a set of formatted records.

This base class returns an empty string, but this may be overridden by subclasses.

<br />

|                       Parameters                        ||
|-----|----------------------------------------------------|
| `h` | `Handler`: The target handler (can be null) <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------|--------------------|
| [String](https://developer.android.com/reference/java/lang/String) | tail string <br /> |