BasicFormatter

public struct BasicFormatter : Formatter

Your basic, customizable log formatter BasicFormatter does not need any setup and will automatically include all log components It can also be given a linear sequence of log components and it will build formatted logs in that order

  • Log format sequential specification

    Declaration

    Swift

    public let format: [LogComponent]
  • Log component separator

    Declaration

    Swift

    public let separator: String?
  • Log timestamp component formatter

    Declaration

    Swift

    public let timestampFormatter: DateFormatter
  • Default timestamp component formatter

    Declaration

    Swift

    public static var timestampFormatter: DateFormatter { get }
  • Default init

    Declaration

    Swift

    public init(_ format: [LogComponent] = LogComponent.allNonmetaComponents, separator: String = " ", timestampFormatter: DateFormatter = BasicFormatter.timestampFormatter)

    Parameters

    _

    Log format specification(default: LogComponent.allNonmetaComponents)

    separator

    Log component separator (default: “ ”)

    timestampFormatter

    Log timestamp component formatter (default: BasicFormatter.timestampFormatter)

  • Our main log formatting method

    Declaration

    Swift

    public func processLog(level: Logger.Level,
                           message: Logger.Message,
                           prettyMetadata: String?,
                           file: String, function: String, line: UInt) -> String

    Parameters

    level

    log level

    message

    actual message

    prettyMetadata

    optional metadata that has already been prettified

    file

    log’s originating file

    function

    log’s originating function

    line

    log’s originating line

    Return Value

    Result of formatting the log

  • apple/swift-log‘s log format

    {timestamp} {level}: {message}

    Example:

    2019-07-30T13:49:07-0400 error: Test error message

    Declaration

    Swift

    public static let apple: BasicFormatter
  • Adorkable’s go-to log format 😘

    {timestamp} â–¶ {level} â–¶ {file}:{line} â–¶ {function} â–¶ {message} â–¶ {metadata}

    Example:

    2019-07-30T13:49:07-0400 â–¶ error â–¶ /asdf/swift-log-format-and-pipe/Tests/LoggingFormatAndPipeTests/FormatterTests.swift:25 â–¶ testFormatter(_:) â–¶ Test error message

    Declaration

    Swift

    public static let adorkable: BasicFormatter