LogFormatter

public protocol LogFormatter : AnyObject

A LogFormatter protocol provides support for formatting LogRecords. Typically each LogHandler will have a LogFormatter associated with it. The LogFormatter takes a LogRecord and converts it to a string. Some formatters (such as the FileLogFormatter) need to put head strings above a set of formatted records. The head property can be used to obtain these strings.

There are 2 default formatters alreadey available:

  1. DefaultLogFormatter -> normally used by a console handler
  2. FileLogFormatter -> normally used by a file handler
  • Provides header data which normally is put above a set of formatted records, e.g. Version info, OS Version.

    Declaration

    Swift

    var head: String { get }
  • Format the given log record and return the formatted string.

    Declaration

    Swift

    func format(_ record: LogRecord) -> String

    Parameters

    record

    the log record to be formatted

    Return Value

    formatted log record

  • Default formatting for date in logs

    Declaration

    Swift

    func formatDate(_ date: Date) -> String

    Parameters

    date

    the date to be formatted

    Return Value

    formatted date