Logger
public class Logger
A logging framework that can print messages to the console, store them locally on the device, and send them to the Mobile Analytics service. With each log message, additional information is gathered such as the file, function, and line where the log was created, as well as the severity of the message.
Multiple Logger instances can be created with different names using logger(name:).
When logging, choose the log method that matches the severity of the message. For example, use debug(message:) for fine-detail information and error(message:) for unintended failures. To limit which logs get printed to the console and stored on the device, set the logLevelFilter property.
To enable logs to be stored locally on the device, set isLogStorageEnabled to true. Logs are added to the log file until the file size is greater than the maxLogStoreSize. At this point, the first half of the stored logs will be deleted to make room for new log data.
To send logs to the Mobile Analytics service, use send(completionHandler:). When the log data is successfully uploaded, the logs will be deleted from local storage.
Note
TheLogger class sets an uncaught exception handler to log application crashes. If you wish to set your own exception handler, do so before calling logger(name:), or the Logger exception handler will be overwritten.
-
The name that identifies this
Loggerinstance.Declaration
Swift
public let name: String -
Logs below this severity level will be ignored, so they will not be recorded or printed to the console. For example, setting the value to
.warnwill record fatal, error, and warn logs, but not info or debug logs.The default value is
LogLevel.debug.Set the value to
LogLevel.noneto turn off all logging.Declaration
Swift
public static var logLevelFilter: LogLevel -
If set to
true, debug logs from Bluemix Mobile Services frameworks will be displayed on the console. This is useful if you need to debug an issue that you believe is related to Bluemix Mobile Services.Declaration
Swift
public static var isInternalDebugLoggingEnabled: Bool -
Determines whether logs get stored locally on the device. Must be set to
trueto be able to later send logs to the Mobile Analytics service.Declaration
Swift
public static var isLogStorageEnabled: Bool -
The maximum file size (in bytes) for log storage. Logs from
Loggerand logs fromAnalyticsare stored in separate files, both of which are limited bymaxLogStoreSize.Declaration
Swift
public static var maxLogStoreSize: UInt64 -
Trueif the app crashed recently due to an uncaught exception.BMSAnalyticsautomatically records uncaught exceptions, so there is no need to change the value of this property manually. It will be set back tofalseafter analytics logs are sent to the server withAnalytics.send(completionHandler:).Declaration
Swift
public static var isUncaughtExceptionDetected: Bool { get set }
-
Creates a Logger instance that will be identified by the supplied name. If a Logger instance with that name was already created, the existing instance will be returned.
Declaration
Swift
public static func logger(name identifier: String) -> LoggerParameters
nameThe name that identifies this Logger instance.
Return Value
A Logger instance.
-
Log at the debug
LogLevel.Note
Do not supply values for the
file,function, orlineparameters. These parameters take default values to automatically record the file, function, and line in which this method was called.Declaration
Swift
public func debug(message: String, file: String = #file, function: String = #function, line: Int = #line)Parameters
messageThe message to log.
-
Log at the info
LogLevel.Note
Do not supply values for the
file,function, orlineparameters. These parameters take default values to automatically record the file, function, and line in which this method was called.Declaration
Swift
public func info(message: String, file: String = #file, function: String = #function, line: Int = #line)Parameters
messageThe message to log.
-
Log at the warn
LogLevel.Note
Do not supply values for the
file,function, orlineparameters. These parameters take default values to automatically record the file, function, and line in which this method was called.Declaration
Swift
public func warn(message: String, file: String = #file, function: String = #function, line: Int = #line)Parameters
messageThe message to log.
-
Log at the error
LogLevel.Note
Do not supply values for the
file,function, orlineparameters. These parameters take default values to automatically record the file, function, and line in which this method was called.Declaration
Swift
public func error(message: String, file: String = #file, function: String = #function, line: Int = #line)Parameters
messageThe message to log.
-
Log at the fatal
LogLevel.Note
Do not supply values for the
file,function, orlineparameters. These parameters take default values to automatically record the file, function, and line in which this method was called.Declaration
Swift
public func fatal(message: String, file: String = #file, function: String = #function, line: Int = #line)Parameters
messageThe message to log.
-
Send the accumulated logs to the Mobile Analytics service.
Logger logs can only be sent if the BMSClient was initialized with
BMSClient.sharedInstance.initialize(bluemixRegion:)from theBMSCoreframework.Declaration
Swift
public static func send(completionHandler userCallback: BMSCompletionHandler? = nil)Parameters
completionHandlerOptional callback containing the results of the send request.
View on GitHub
Logger Class Reference