# Class OneLineFormatter

java.lang.Object
java.util.logging.Formatter
org.apache.juli.OneLineFormatter

Direct Known Subclasses:
  `JsonFormatter`

public class OneLineFormatter extends Formatter
Provides same information as default log format but on a single line to make it easier to grep the logs. The only exception is stacktraces which are always preceded by whitespace to make it simple to skip them.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `OneLineFormatter()`
  Constructs a OneLineFormatter with the default time format from the log manager properties.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addTimestamp(StringBuilder buf, long timestamp)`
  Adds a formatted timestamp to the given buffer.
  `String`
  `format(LogRecord record)`
  `protected static String`
  `getThreadName(long logRecordThreadId)`
  LogRecord has threadID but no thread name.
  `String`
  `getTimeFormat()`
  Obtain the format currently being used for time stamps in log messages.
  `protected String`
  `resolveThreadName(LogRecord record)`
  Resolves the thread name for a log record, handling async handler cases.
  `void`
  `setTimeFormat(String timeFormat)`
  Specify the time format to use for time stamps in log messages.

  ### Methods inherited from class Formatter

  `formatMessage, getHead, getTail`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### OneLineFormatter

    public OneLineFormatter()
    Constructs a OneLineFormatter with the default time format from the log manager properties.

- ## Method Details

  - ### setTimeFormat

    public void setTimeFormat(String timeFormat)
    Specify the time format to use for time stamps in log messages.
    Parameters:
      `timeFormat` - The format to use using the `SimpleDateFormat` syntax

  - ### getTimeFormat

    public String getTimeFormat()
    Obtain the format currently being used for time stamps in log messages.
    Returns:
      The current format in `SimpleDateFormat` syntax

  - ### format

    public String format(LogRecord record)
    Specified by:
      `format` in class `Formatter`

  - ### resolveThreadName

    protected String resolveThreadName(LogRecord record)
    Resolves the thread name for a log record, handling async handler cases.
    Parameters:
      `record` - The log record
    Returns:
      The resolved thread name

  - ### addTimestamp

    protected void addTimestamp(StringBuilder buf, long timestamp)
    Adds a formatted timestamp to the given buffer.
    Parameters:
      `buf` - The string builder to append to
      `timestamp` - The timestamp in milliseconds

  - ### getThreadName

    protected static String getThreadName(long logRecordThreadId)
    LogRecord has threadID but no thread name.
    Parameters:
      `logRecordThreadId` - the thread id
    Returns:
      the thread name