Logger

public class Logger

A logging class that can be told where to log to via transports.

Features include:

  • Asynchronous, ordered output to transports
  • All log messages can be tagged and filtered
  • LogLevels are provided as well
  • Force logging enables output via print even if no transports available

Filtering

Two methods exist to allow for filtering of the log stream.

  • Shared logger object

    Declaration

    Swift

    public static let shared: Logger
  • Initializes a Logger object

    Declaration

    Swift

    public init(label: String? = nil)
  • Transports are called asynchronously, if you need to wait till all logging output has been sent to all transports then this function blocks until that happens

    Declaration

    Swift

    public func waitTillAllLogsTransported()
  • Set to true if you want the tags to be printed as well

    Declaration

    Swift

    public var outputTags: Bool { get set }
  • If this is false then it ignores all logs

    Declaration

    Swift

    public var enabled: Bool { get set }
  • Adding a transport allows you to tell the logger where the output goes to. You may add as many as you like.

    Declaration

    Swift

    public func addTransport(_ transport: @escaping (String) -> Void)

    Parameters

    transport

    function that is called with each log invocaton

  • Removes all transports

    Declaration

    Swift

    public func removeTransports()
  • Filters log messages unless they are tagged with tag

    Declaration

    Swift

    public func filterUnless(tag: String)
  • Filters log messages unless they are tagged with any of tags

    Declaration

    Swift

    public func filterUnless(tags: [String])
  • Filters log messages if they are tagged with tag

    Declaration

    Swift

    public func filterIf(tag: String)
  • Filters log messages if they are tagged with any of tags

    Declaration

    Swift

    public func filterIf(tags: [String])