ColorizingLogFormatter

public struct ColorizingLogFormatter: LogFormatter

Wraps another LogFormatter and colorizes its output according to the LogSeverity of the LogEntry being recorded.

  • The LogFormatter wrapped by the receiver.

    Declaration

    Swift

    public let formatter: LogFormatter
  • The TextColorizer used to apply color formatting to the output of the receiver’s formatter.

    Declaration

    Swift

    public let colorizer: TextColorizer
  • The ColorTable used to supply foreground and background text color information.

    Declaration

    Swift

    public let colorTable: ColorTable
  • Initializes a new ColorizingLogFormatter instance.

    Declaration

    Swift

    public init(formatter: LogFormatter, colorizer: TextColorizer, colorTable: ColorTable? = nil)

    Parameters

    formatter

    The LogFormatter whose output will be colorized by the receiver.

    colorizer

    The TextColorizer that will be used to colorize the output of formatter.

    colorTable

    The ColorTable to use for supplying color information to the TextColorizer.

  • Formats the LogEntry by first passing it to the LogFormatter used to construct the receiver. Then, if a non-nil value is returned, the resulting string have color formatting codes applied to it using the colorizer and colorTable specified at instantiation.

    Declaration

    Swift

    public func format(_ entry: LogEntry)
            -> String?

    Parameters

    entry

    The LogEntry to be formatted.

    Return Value

    The formatted result, or nil if the receiver’s formatter returns nil when attempting to format entry.