How to enable SDK logging for troubleshooting purposes - infobip/mobile-messaging-sdk-ios GitHub Wiki
Cocoapods
If you are using Cocoapods, by adding pod 'MobileMessaging'
in your Podfile, CocoaLumberjack logging will be enabled automatically,
for debug builds it prints logs for the level >= .Info
to the console,
for release builds it saves logs for the level >= .Warning
to the file.
If you don't want to use CocoaLumberjack logging, you can install a Core version of MobileMessaging SDK. In your Podfile
use the following code:
pod 'MobileMessaging/Core'
Put this line before starting Mobile Messaging SDK:
MobileMessaging.logger = MMDefaultLogger()
Carthage
If you are using Carthage, put this line before starting Mobile Messaging SDK, to enable default logger
MobileMessaging.logger = MMDefaultLogger()
or this, if you want to enable CocoaLumberjack logger:
MobileMessaging.logger = MMLumberjackLogger(logOutput: .Console, logLevel: .Debug)
Swift Package Manager
If you are using Swift Package Manager to enable CocoaLumberjack logging add MobileMessagingLumberjack
module.
Then, put this line before starting the Mobile Messaging SDK, specify logOutput
and logLevel
options:
MobileMessaging.logger = MMLumberjackLogger(logOutput: .Console, logLevel: .Debug)
To enable default logging add MobileMessaging
module, put this line before starting Mobile Messaging SDK:
MobileMessaging.logger = MMDefaultLogger()
Customization
If you'd like to change logger options use MMLogging API
MobileMessaging.logger?.logLevel = .Warning
MobileMessaging.logger?.logOutput = .File
Also, you can use your own logging tool by implementing the MMLogging
protocol and setting your logger as a MobileMessaging default logger:
class CustomMagicLogger: MMLogging {
var logOutput: MMLogOutput { ... }
var logLevel: MMLogLevel { ... }
var logFilePath: String? { ... }
func sendLogs(fromViewController vc: UIViewController) { ... }
func logDebug(message: String) { ... }
func logInfo(message: String) { ... }
func logError(message: String) { ... }
func logWarn(message: String) { ... }
func logVerbose(message: String) { ... }
}
...
MobileMessaging.logger = CustomMagicLogger()