Logger
public final class Logger
If clients want to use the same log formatting and logger features of LipikaEngine, they are free to use this class.
Logger exposes a thread-local instance called Logger.log
that needs to be used. Logger itself cannot be instantiated.
Important
logLevel
is thread-local specific and not global.
Note
message strings passed into Logger are @autoclosure and hence are not evaluated unless they are logged.Usage
Logger.logLevel = .warning
Logger.log.debug("you don't need to know")
Logger.log.warning("you may want to know")
-
Enumeration of logging levels in the decreasing order of verbosity and increasing order of importance:
See moreLevel.debug
,Level.warning
,Level.error
,Level.fatal
.Declaration
Swift
public enum Level : String
-
Thread-local singleton instance of Logger that clients must use.
Logger
itself cannot be instantiated.Declaration
Swift
public static var log: Logger { get }
-
Get or set the level at and after which logs will be recorded. Levels with decreasing verbosity and increasing importance are
Level.debug
,Level.warning
,Level.error
andLevel.fatal
. When a level of certain level of verbosity is set, all levels at and with lower verbosity are recorded.Declaration
Swift
public static var logLevel: Level { get set }
Return Value
Level or defaults to
Level.warning
if a log level has not been set on this thread -
Log the given message at
Level.debug
level of importanceDeclaration
Swift
public func debug(_ message: @autoclosure() -> String)
-
Log the given message at
Level.warning
level of importanceDeclaration
Swift
public func warning(_ message: @autoclosure() -> String)
-
Log the given message at
Level.error
level of importanceDeclaration
Swift
public func error(_ message: @autoclosure() -> String)
-
Log the given message at
Level.fatal
level of importanceDeclaration
Swift
public func fatal(_ message: @autoclosure() -> String)
-
Start capturing all messages that is also going to be logged. This is useful for programatically inspecting or showing logs to end users.
Throws
LoggerError.alreadyCapturing if this method is double invokedDeclaration
Swift
public func startCapture() throws
-
End capturing logs.
Declaration
Swift
public func endCapture() -> [String]?
Return Value
list of messages that were logged at or above the specified
logLevel
.