# SimpleFormatter

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

# SimpleFormatter

`
public


class
SimpleFormatter
`  
`


``

extends `[Formatter](https://developer.android.com/reference/java/util/logging/Formatter)`


``


`

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

<br />

*** ** * ** ***

Print a brief summary of the`LogRecord`in a human readable format. The summary will typically be 1 or 2 lines.

**Configuration:**The`SimpleFormatter`is initialized with the[format string](https://developer.android.com/reference/java/util/Formatter.html#syntax)specified in the`java.util.logging.SimpleFormatter.format`property to[format](https://developer.android.com/reference/java/util/logging/SimpleFormatter#format(java.util.logging.LogRecord))the log messages. This property can be defined in the[logging properties](https://developer.android.com/reference/java/util/logging/LogManager#getProperty(java.lang.String))configuration file or as a system property. If this property is set in both the logging properties and system properties, the format string specified in the system property will be used. If this property is not defined or the given format string is[illegal](https://developer.android.com/reference/java/util/IllegalFormatException), the default format is implementation-specific.  
**See also:**

- [Formatter](https://developer.android.com/reference/java/util/Formatter)

## Summary

|                                                  ### Public constructors                                                  ||
|------------------------------------------------------------------------------------------------------------------------|---|
| ` `[SimpleFormatter](https://developer.android.com/reference/java/util/logging/SimpleFormatter#SimpleFormatter())`() ` |

|                                                                                                                                                     ### Public methods                                                                                                                                                      ||
|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[String](https://developer.android.com/reference/java/lang/String) | ` `[format](https://developer.android.com/reference/java/util/logging/SimpleFormatter#format(java.util.logging.LogRecord))`(`[LogRecord](https://developer.android.com/reference/java/util/logging/LogRecord)` record) ` Format the given LogRecord. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.util.logging.Formatter](https://developer.android.com/reference/java/util/logging/Formatter)` ` |--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` 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.                           | ||
| 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*.                                                                                             | ||

## Public constructors

### SimpleFormatter

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

```
public SimpleFormatter ()
```

<br />

<br />

## Public methods

### format

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

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

Format the given LogRecord.

The formatting can be customized by specifying the[format string](https://developer.android.com/reference/java/util/Formatter.html#syntax)in the[`java.util.logging.SimpleFormatter.format`](https://developer.android.com/reference/java/util/logging/SimpleFormatter#formatting)property. The given`LogRecord`will be formatted as if by calling:  

        https://developer.android.com/reference/java/lang/String#format(java.lang.String,%20java.lang.Object[])(format, date, source, logger, level, message, thrown);
     
where the arguments are:  

1. `format`- the[java.util.Formatter](https://developer.android.com/reference/java/util/Formatter)format string specified in the`java.util.logging.SimpleFormatter.format`property or the default format.
2. `date`- a[Date](https://developer.android.com/reference/java/util/Date)object representing[event time](https://developer.android.com/reference/java/util/logging/LogRecord#getMillis())of the log record.
3. `source`- a string representing the caller, if available; otherwise, the logger's name.
4. `logger`- the logger's name.
5. `level`- the[log level](https://developer.android.com/reference/java/util/logging/Level#getLocalizedName()).
6. `message`- the formatted log message returned from the[Formatter.formatMessage(LogRecord)](https://developer.android.com/reference/java/util/logging/Formatter#formatMessage(java.util.logging.LogRecord))method. It uses[java.text](https://developer.android.com/reference/java/text/MessageFormat)formatting and does not use the`java.util.Formatter
   format`argument.
7. `thrown`- a string representing the[throwable](https://developer.android.com/reference/java/util/logging/LogRecord#getThrown())associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.

Some example formats:  

- `java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"`

  This prints 1 line with the log level (`4$`), the log message (`5$`) and the timestamp (`1$`) in a square bracket.  

  ```
       WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011]
       
  ```
- `java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"`

  This prints 2 lines where the first line includes the timestamp (`1$`) and the source (`2$`); the second line includes the log level (`4$`) and the log message (`5$`) followed with the throwable and its backtrace (`6$`), if any:  

  ```
       Tue Mar 22 13:11:31 PDT 2011 MyClass fatal
       SEVERE: several message with an exception
       java.lang.IllegalArgumentException: invalid argument
               at MyClass.mash(MyClass.java:9)
               at MyClass.crunch(MyClass.java:6)
               at MyClass.main(MyClass.java:3)
       
  ```
- `java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%n"`

  This prints 2 lines similar to the example above with a different date/time formatting and does not print the throwable and its backtrace:  

  ```
       Mar 22, 2011 1:11:31 PM MyClass fatal
       SEVERE: several message with an exception
       
  ```

This method can also be overridden in a subclass. 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) | a formatted log record <br /> |