LogService
@objc public class LogService: NSObject
The LogService class allows the client app to control how log messages generated by the libraries are handled.
Messages are logged via the LogVerbose, Log, LogWarning, and LogError functions and the app can control each of these independently by adding event handlers to the appropriate events. The app can also control which events are emitted with the verbosity property.
Note: By default if no log handlers are registered then nothing will be logged. The app can register log handling functions and change the verbosity level at any time but it is recommended to do so as early as possible or some logs could be missed.
Example: Initializing the log service in the AppDelegate
let logHandler = LogHandler({ (item: Any) -> Void in
print(item)
})
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
LogService.verbosity = LogService.LogLevel.Verbose
LogService.addLogVerboseHandler(logHandler)
LogService.addLogHandler(logHandler)
LogService.addLogWarningHandler(logHandler)
LogService.addLogErrorHandler(logHandler)
return true
}
-
The different log levels for messages.
See moreDeclaration
Swift
@objc public enum LogLevel: Int -
The log level used to determine which messages are sent to the registered handlers.
Declaration
Swift
public static var verbosity = LogLevel.None -
Adds a log handler for messages logged using the ‘logVerbose’ method.
Declaration
Swift
public static func addLogVerboseHandler(_ handler: LogHandler) -
Removes a log handler for messages logged using the ‘logVerbose’ method.
Declaration
Swift
public static func removeLogVerboseHandler(_ handler: LogHandler) -
Adds a log handler for messages logged using the ‘log’ method.
Declaration
Swift
public static func addLogHandler(_ handler: LogHandler) -
Removes a log handler for messages logged using the ‘log’ method.
Declaration
Swift
public static func removeLogHandler(_ handler: LogHandler) -
Adds a log handler for messages logged using the ‘logWarning’ method.
Declaration
Swift
public static func addLogWarningHandler(_ handler: LogHandler) -
Removes a log handler for messages logged using the ‘logWarning’ method.
Declaration
Swift
public static func removeLogWarningHandler(_ handler: LogHandler) -
Adds a log handler for messages logged using the ‘logError’ method.
Declaration
Swift
public static func addLogErrorHandler(_ handler: LogHandler) -
Removes a log handler for messages logged using the ‘logError’ method.
Declaration
Swift
public static func removeLogErrorHandler(_ handler: LogHandler) -
Logs verbose debug messages.
Declaration
Swift
public static func logVerbose(_ item: Any)Parameters
itemThe item to be logged.
-
Logs debug messages.
Declaration
Swift
public static func log(_ item: Any)Parameters
itemThe item to be logged.
-
Logs a warning message.
Declaration
Swift
public static func logWarning(_ item: Any)Parameters
itemThe item to be logged.
-
Logs an error message.
Declaration
Swift
public static func logError(_ item: Any)Parameters
itemThe item to be logged.
LogService Class Reference