LoggerProtocol Protocol Reference
public protocol LoggerProtocol
A central utility class for processing log statements at various log levels.
Log messages are not guaranteed to be processed immediately upon calling one of the logging methods, however they will be processed in the order that they are received.
Important: When using the logging methods, always use a limited set of non-dynamic categories. Categories should be static strings that identify the component or feature being logged (e.g., “NetworkModule”, “TraceModule”). Avoid using dynamic values like user IDs, timestamps, or other variable data as categories, as this can lead to performance issues and potential memory problems in logging implementations.
-
Asynchronously determines whether or not the given
levelshould be logged by the currently configuredLogLevel.Minimum.This method executes asynchronously to ensure thread-safe access to the logger’s internal state. The result is delivered via the completion handler.
Note: The completion handler will be called with
truewhen there is not aLogLevel.Minimumset yet. Therefore, calling any of the logging methods (trace,debugetc) will queue the log message until aLogLevel.Minimumhas been set, deferring the decision on whether to log, or not, until then.Declaration
Swift
func shouldLog(level: LogLevel, completion: @escaping (Bool) -> Void)Parameter Description levelThe
LogLevelto compare against the currently configuredLogLevel.Minimum.completionA closure called asynchronously with the result of whether the level should be logged.
-
Logs a
tracelevel message by evaluating the message passed in an autoclosure when and if log needs to take place.Declaration
Swift
func trace(category: String, _ messageProvider: @autoclosure @escaping () -> String)Parameter Description categoryThe category or identifier associated with the log message.
messageProviderThe message to be recorded, only evaluated when and if log needs to take place.
-
Logs a
debuglevel message by evaluating the message passed in an autoclosure when and if log needs to take place.Declaration
Swift
func debug(category: String, _ messageProvider: @autoclosure @escaping () -> String)Parameter Description categoryThe category or identifier associated with the log message.
messageProviderThe message to be recorded, only evaluated when and if log needs to take place.
-
Logs an
infolevel message by evaluating the message passed in an autoclosure when and if log needs to take place.Declaration
Swift
func info(category: String, _ messageProvider: @autoclosure @escaping () -> String)Parameter Description categoryThe category or identifier associated with the log message.
messageProviderThe message to be recorded, only evaluated when and if log needs to take place.
-
Logs a
warnlevel message by evaluating the message passed in an autoclosure when and if log needs to take place.Declaration
Swift
func warn(category: String, _ messageProvider: @autoclosure @escaping () -> String)Parameter Description categoryThe category or identifier associated with the log message.
messageProviderThe message to be recorded, only evaluated when and if log needs to take place.
-
Logs an
errorlevel message by evaluating the message passed in an autoclosure when and if log needs to take place.Declaration
Swift
func error(category: String, _ messageProvider: @autoclosure @escaping () -> String)Parameter Description categoryThe category or identifier associated with the log message.
messageProviderThe message to be recorded, only evaluated when and if log needs to take place.
-
Logs the provided level message by evaluating the message passed in an autoclosure when and if log needs to take place.
Declaration
Swift
func log(level: LogLevel, category: String, _ messageProvider: @autoclosure @escaping () -> String)Parameter Description levelThe level of the log.
categoryThe category or identifier associated with the log message.
messageProviderThe message to be recorded, only evaluated when and if log needs to take place.