SwiftSwift Native SDK Troubleshooting Guide

These docs are for the new PubNub Swift SDK written purely in Swift. To view the docs for the older version (the PubNub Objective-C SDK wrapper for Swift), have a look here.
Use the following code to enable logging:

PubNub.log.levels = [.all]
PubNub.log.writers = [ConsoleLogWriter(), FileLogWriter()]

The PubNub log runner is a singleton instance, and should be configured once at the beginning of your app's lifecycle. Changing log properties will overwrite their previous entries.

You can configure log levels by assigning the PubNub.log.writers array property to your desired log levels.

Use the following code to enable console and file output:

PubNub.log.writers = [ConsoleLogWriter(), FileLogWriter()]

By default, the FileLogWriter attempts to log to the user's cache directory. For more information, refer to the Apple documentation on the domain constants and search paths for the significant directories.

Use the following code to enable log file output using a URL:

if let url = URL(string: "file:///path/to/pubnub/logs/") {
  PubNub.log.writers = [FileLogWriter(logDirectory: url)]

Use the following code to enable file output using FileManager:

PubNub.log.writers = [FileLogWriter(inside: .allDomainsMask, at: .applicationDirectory, with: 'directoryName')]

You can create a custom log writer if you want to output logs to a location other than the console or local file system.

To create a custom log writer, implement the LogWriter protocol, then add an instance of your custom writer to the PubNub.log.writers property.

Log levels are as follows:

Log LevelBitmaskDescription
none0Logging is disabled.
debug1 << 0May be useful during development or while troubleshooting a specific problem.

Warning! Debug logging is intended for use in a development environment. Do not use it shipping software.
info1 << 1Information that may be helpful, but isn’t essential, for troubleshooting errors.
event1 << 2Logs as part of an event stream
warn1 << 3Designates potentially harmful situations.
error1 << 4Error-level messages are intended for reporting process-level errors. If an activity object exists, logging at this level captures information for the entire process chain.
log1 << 31This is a special category used to log errors that occur internal to the logger.
allUInt32.maxAll log levels will be captured

Configure log levels by assigning the PubNub.log.levels array property to your desired log levels, as in the following examples.