Logger
public class Logger
The logger class is used within the library to output logs of what is going on. Multi-threading and task management is very complicated and having logs can help immensely when it comes to debugging purposes
Everytime the log function is called, a number of tags are automatically produced that are attached to the message. These are:
- the function name that the log is called from
- The thread that the log is called from (UI or BG - for background)
- The filename
- The log level (see
LogLevel
)
This class is also made public so the API is meant to be stable
There’re also a number of predefined tags that the logs from within the library use. See LogTags
for a list.
-
Shared logger object
Declaration
Swift
public static let shared: Logger
-
Initializes a Logger object
Declaration
Swift
public init(logHistorySize: Int? = nil, synchronousOutput: Bool = false)
Parameters
logHistorySize
How many entried to keep in the history
-
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
-
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])
-
Logs any
T
by using string interpolationDeclaration
Swift
public func log<T>( level: LogLevel = .info, _ object: @autoclosure () -> T, tag: String, force: Bool = false, _ file: String = #file, _ function: String = #function, _ line: Int = #line )
Parameters
object
autoclosure statment to be logged
tag
a tag to apply to this log
-
Logs any
T
by using string interpolationDeclaration
Swift
public func log<T>( level: LogLevel = .info, _ object: @autoclosure () -> T, tags: [String] = [], force: Bool = false, _ file: String = #file, _ function: String = #function, _ line: Int = #line )
Parameters
object
autoclosure statment to be logged
tags
a set of tags to apply to this log