Check the Log Output

The SDK uses extensive internal logging to record actions it performs for informational and diagnostic purposes. General logging is always enabled. The SDK also writes error and fault-level logs when certain conditions occur. Add this code to your app to enable logging.

1// Turn on logging by selecting the logLevel (debug, warn or error). Debugging is not recommended for production apps.
2SFMCSdk.setLogger(logLevel: .debug)
1// turn on logging for debugging.  Not recommended for production apps.
2// Set to true to enable logging while debugging
3MarketingCloudSDK.sharedInstance().sfmc_setDebugLoggingEnabled(true)

You can also enable logging with CustomLogOutputter, as shown in this example.

1class CustomLogOutputter: LogOutputter {
2    override func out(level: LogLevel, subsystem: String, category: LoggerCategory, message: String) {
3        // custom log outputting code
4    }
5}
6
7// Then set the log level and custom log outputter
8SFMCSdk.setLogger(logLevel: .debug, logOutputter: CustomLogOutputter())

Standard Log Output 

Alternatively, you can enable logging with a standard log output and a log filter, as shown in this example.

1SFMCSdk.setLogger(logLevel: .debug, logOutputter: LogOutputter(), filters: [.module, .identity])

To clear previously set filtering options, use this code.

1SFMCSdk.clearLoggerFilters()

To query the state of debug-level logging, use this code.

1let enabled = MarketingCloudSDK.sharedInstance().sfmc_getDebugLoggingEnabled()

The SDK sends all logging output to Apple’s unified logging system. Review this information on the Devices and Simulators window in Xcode, or in the macOS Console app. If SDK debug logging is enabled, the SDK uses the OS_LOG_TYPE_DEBUG value.

Disable logging before you submit a release build to the App Store.

See Also