---
source_url: https://www.pubnub.com/docs/sdks/objective-c/logging
title: Logging for Objective-C SDK
updated_at: 2026-06-19T11:38:03.389Z
sdk_name: PubNub Objective-C SDK
sdk_version: 7.0.3
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Logging for Objective-C SDK

PubNub Objective-C SDK, use the latest version: 7.0.3

Install:

```bash
pod install PubNub@7.0.3
```

This page explains how to configure logging in the PubNub Objective-C Software Development Kit (SDK) for iOS and macOS applications. Logging helps you monitor SDK activity, troubleshoot issues, and maintain audit trails during development and production.

For general logging concepts and best practices applicable to all PubNub SDKs, see [Logging](https://www.pubnub.com/docs/general/setup/logging).

:::warning Logging in pre-6.0.0 versions
This logging documentation applies to Objective-C SDK version 6.0.0 and later. Older versions used the legacy `[PNLog enabled:YES]` method, which is no longer supported.
:::

## Logging architecture

The Objective-C SDK provides a flexible logging system with the following features:

* Built-in loggers: The SDK includes a console logger (`PNConsoleLogger`) that prints to Xcode console and a file logger (`PNFileLogger`) that writes to disk with automatic rotation.
* Custom loggers: Implement the `PNLogger` protocol to route logs to external monitoring services, databases, or analytics platforms.
* Multiple logger support: Use built-in and custom loggers simultaneously. All registered loggers receive the same log entries.
* Structured log entries: Each log includes an instance identifier, timestamp, log level, operation type, and typed content.

Logging is disabled by default (`PNNoneLogLevel`) to optimize performance in production environments.

## Log levels

The SDK uses standard log levels to control the amount of detail captured:

| Level | Purpose |
| --- | --- |
| `PNNoneLogLevel` | Logging disabled. Default setting. |
| `PNTraceLogLevel` | Internal operations including method calls, state-machine transitions, and detailed execution flow. |
| `PNDebugLogLevel` | User inputs, API (Application Programming Interface) parameters, HTTP (Hypertext Transfer Protocol) requests and responses, and operation results. |
| `PNInfoLogLevel` | Significant events including successful initialization and configuration changes. |
| `PNWarnLogLevel` | Deprecation warnings, unusual conditions, and non-breaking validation warnings. |
| `PNErrorLogLevel` | Errors, exceptions, and configuration conflicts. |

Each level automatically includes messages from all higher severity levels. The hierarchy is: `ERROR` → `WARN` → `INFO` → `DEBUG` → `TRACE`.

:::warning Logging sensitive information
The `PNDebugLogLevel` and `PNTraceLogLevel` settings may log sensitive information including API keys, user identifiers, and message content. Use these levels only in development environments. Never enable `DEBUG` or `TRACE` logging in production environments with sensitive data.
:::

## Enable logging

Configure logging when creating your PubNub client by setting the `logLevel` property on the configuration object.

```objectivec
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                                 subscribeKey:@"demo"
                                                                       userID:@"myUniqueUserID"];

// Set log level to DEBUG
configuration.logLevel = PNDebugLogLevel;

PubNub *client = [PubNub clientWithConfiguration:configuration];
```

### Change log level at runtime

Adjust the log level after initialization using the `setLogLevel:` method:

```objectivec
// Increase detail for troubleshooting
[self.client setLogLevel:PNTraceLogLevel];

// Reduce detail after resolving issues
[self.client setLogLevel:PNErrorLogLevel];

// Disable logging
[self.client setLogLevel:PNNoneLogLevel];
```

## Logged information

The SDK logs information at various stages of operation:

### API call parameters

The SDK logs all user-provided input data for each API call at the `PNDebugLogLevel` setting. These logs help identify mismatches between expected and actual parameters.

Example log:

```text
[PubNub-a1b2c3] DEBUG - Manage push-enabled channels with parameters:
{
    channels = ["channel-a", "channel-b"];
    deviceToken = "<token-data>";
    pushType = "APNS2";
}
```

### Network requests and responses

The SDK logs complete HTTP transaction information at the `PNDebugLogLevel` setting.

#### Request logs

* HTTP method: GET, POST, PATCH, or DELETE
* Complete URL with query parameters
* Request headers as key-value pairs
* Request body content for POST, PUT, or PATCH requests
* Timestamp with millisecond precision

#### Response logs

* HTTP status code
* Response body content
* Request URL for correlation with the originating request
* Timestamp when the SDK received the response

### Operation results

The SDK logs success and failure messages for API operations at the `PNDebugLogLevel` setting.

Example success log:

```text
[PubNub-a1b2c3] DEBUG - Manage push-enabled channels success.
```

Example failure log:

```text
[PubNub-a1b2c3] ERROR - Failed to process request: Network connection lost
```

### Errors and warnings

The SDK logs errors at the `PNErrorLogLevel` setting and warnings at the `PNWarnLogLevel` setting.

Example error log:

```text
[PubNub-a1b2c3] ERROR - It is expected that only cipherKey or cryptoModule will be 
configured at once. PubNub client will use the configured cryptoModule.
```

## Log entry structure

Each log entry includes:

| Component | Description |
| --- | --- |
| Instance identifier | Format: `PubNub-{shortId}` where `shortId` represents the first 6 characters of the instance UUID (Universally Unique Identifier). Use this identifier to filter logs from multiple SDK instances. |
| Log level | The severity level: `TRACE`, `DEBUG`, `INFO`, `WARN`, or `ERROR`. |
| Location | The SDK component generating the log entry, such as "PubNub". |
| Timestamp | The date and time when the SDK created the log entry. |
| Message | The log content describing the operation or event. |
| Message type | The data type: PNTextLogMessageType (PNStringLogEntry), PNObjectLogMessageType (PNDictionaryLogEntry), PNErrorLogMessageType (PNErrorLogEntry), PNNetworkRequestLogMessageType (PNNetworkRequestLogEntry), PNNetworkResponseLogMessageType (PNNetworkResponseLogEntry) |
| Operation | The API operation associated with the log, such as subscribe, publish, or presence. |

### Filter logs from multiple instances

Applications that create multiple PubNub instances can filter logs using the instance identifier.

```objectivec
// First instance
PubNub *client1 = [PubNub clientWithConfiguration:config1];
// Log entries display: [PubNub-a1b2c3] ...

// Second instance
PubNub *client2 = [PubNub clientWithConfiguration:config2];
// Log entries display: [PubNub-d4e5f6] ...
```

Filter the Xcode console by entering the specific instance identifier in the search field.

## Built-in loggers

### Console logger

The `PNConsoleLogger` prints log entries to the Xcode console. The SDK enables this logger by default when you set a log level other than `PNNoneLogLevel`.

To disable the console logger:

```objectivec
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                                 subscribeKey:@"demo"
                                                                       userID:@"myUniqueUserID"];
configuration.logLevel = PNDebugLogLevel;
configuration.enableDefaultConsoleLogger = NO;  // Disable default logger output to the Xcode console

PubNub *client = [PubNub clientWithConfiguration:configuration];
```

### File logger

The `PNFileLogger` writes log entries to disk with automatic rotation. Use this logger for production environments where console output is not available.

```objectivec
#import <PubNub/PNFileLogger.h>

// Specify log directory path
NSString *logsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                                          NSUserDomainMask, 
                                                          YES).firstObject 
                      stringByAppendingPathComponent:@"PubNubLogs"];

// Create file logger
PNFileLogger *fileLogger = [PNFileLogger loggerWithLogsDirectoryPath:logsPath];

// Configure rotation settings
fileLogger.maximumLogFileSize = 5 * 1024 * 1024;      // 5 MB per file
fileLogger.maximumNumberOfLogFiles = 10;               // Keep 10 files
fileLogger.logFilesDiskQuota = 50 * 1024 * 1024;      // 50 MB total

// Add to configuration
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                                 subscribeKey:@"demo"
                                                                       userID:@"myUniqueUserID"];
configuration.logLevel = PNDebugLogLevel;
configuration.loggers = @[fileLogger];

PubNub *client = [PubNub clientWithConfiguration:configuration];
```

#### File logger properties

| Property | Description |
| --- | --- |
| `maximumLogFileSize`Default: 1 MB | Maximum single log file size in bytes. The logger creates a new file when this limit is reached. |
| `maximumNumberOfLogFiles`Default: 5 | Maximum number of log files to retain after rotation. The logger deletes the oldest files when this limit is exceeded. |
| `logFilesDiskQuota`Default: 20 MB | Maximum total size of the logs directory in bytes. The logger removes old files to maintain this quota. |

## Custom loggers

Create custom loggers to route log entries to external monitoring services, databases, or analytics platforms. Custom loggers must implement the `PNLogger` protocol.

### PNLogger protocol

The `PNLogger` protocol defines five methods:

```objectivec
@protocol PNLogger <NSObject>

- (void)traceWithMessage:(PNLogEntry *)message;
- (void)debugWithMessage:(PNLogEntry *)message;
- (void)infoWithMessage:(PNLogEntry *)message;
- (void)warnWithMessage:(PNLogEntry *)message;
- (void)errorWithMessage:(PNLogEntry *)message;

@end
```

Each method receives a `PNLogEntry` object with the following properties:

| Property | Description |
| --- | --- |
| `message` | The log payload. Can be a string, dictionary, error, network request, or network response. |
| `messageType` | The message type indicating the data structure of the `message` property. |
| `operation` | The API operation such as subscribe, publish, or presence. |
| `logLevel` | The log level: trace, debug, info, warn, or error. |
| `minimumLogLevel` | The minimum log level configured for the client instance. |
| `pubNubId` | The PubNub instance identifier. |
| `location` | The SDK component generating the log entry. |
| `timestamp` | The date and time when the SDK created the log entry. |
| `details` | Optional additional context for the log entry. |

### Custom logger example

```objectivec
#import <PubNub/PubNub.h>

@interface MonitoringLogger : NSObject <PNLogger>
@end

@implementation MonitoringLogger

- (void)errorWithMessage:(PNLogEntry *)message {
    // Handle errors
    if (message.messageType == PNErrorLogMessageType) {
        NSError *error = (NSError *)message.message;
        
        // Send to monitoring service
        [self.monitoringService reportError:error.localizedDescription
                                 instanceId:message.pubNubId
                                  timestamp:message.timestamp
                                   location:message.location];
    }
}

- (void)warnWithMessage:(PNLogEntry *)message {
    // Handle warnings (e.g., deprecations)
    if (message.messageType == PNTextLogMessageType) {
        NSString *warning = (NSString *)message.message;
        [self.monitoringService logWarning:warning];
    }
}

- (void)debugWithMessage:(PNLogEntry *)message {
    // Track API usage patterns
    if (message.messageType == PNObjectLogMessageType) {
        NSDictionary *data = (NSDictionary *)message.message;
        [self.analyticsService trackAPICall:message.operation 
                                 parameters:data
                                 instanceId:message.pubNubId];
    }
}

- (void)traceWithMessage:(PNLogEntry *)message {
    // Detailed tracing for performance analysis
}

- (void)infoWithMessage:(PNLogEntry *)message {
    // Track significant events
}

@end

// Configure with custom logger
MonitoringLogger *customLogger = [[MonitoringLogger alloc] init];

PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                                 subscribeKey:@"demo"
                                                                       userID:@"myUniqueUserID"];
configuration.logLevel = PNDebugLogLevel;
configuration.loggers = @[customLogger];

PubNub *client = [PubNub clientWithConfiguration:configuration];
```

### Use multiple loggers

Use the built-in console logger and custom loggers simultaneously:

```objectivec
MonitoringLogger *customLogger = [[MonitoringLogger alloc] init];

PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                                 subscribeKey:@"demo"
                                                                       userID:@"myUniqueUserID"];
configuration.logLevel = PNDebugLogLevel;
configuration.loggers = @[customLogger];         // Add custom logger

PubNub *client = [PubNub clientWithConfiguration:configuration];
```

The SDK sends every log entry that meets the minimum log level threshold to all registered loggers.

## Logging best practices

### Choose the appropriate log level

| Environment | Recommended Log Level |
| --- | --- |
| Production | `PNErrorLogLevel` to capture critical issues without performance impact. |
| Staging | `PNInfoLogLevel` to monitor operational events. |
| Development | `PNDebugLogLevel` to investigate issues and verify behavior. |
| Deep troubleshooting | `PNTraceLogLevel` when working with PubNub support on complex issues. |

### Protect sensitive data

Never enable `PNDebugLogLevel` or `PNTraceLogLevel` in production environments that handle sensitive information.

These levels may expose:

* API keys and authentication tokens
* User identifiers and personal information
* Message content and metadata

### Filter logs by instance identifier

Use the instance identifier to filter logs when debugging applications with multiple PubNub clients. Enter the instance identifier in the Xcode console search field to view logs from a specific instance.

### Use file logger in production

Use `PNFileLogger` instead of console logging in production environments:

```objectivec
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:publishKey
                                                                 subscribeKey:subscribeKey
                                                                       userID:userID];
configuration.logLevel = PNErrorLogLevel;                    // Capture errors only
configuration.enableDefaultConsoleLogger = NO;               // Disable default logger output to the Xcode console
configuration.loggers = @[[PNFileLogger loggerWithLogsDirectoryPath:logsPath]];

PubNub *client = [PubNub clientWithConfiguration:configuration];
```

### Optimize logging performance

Disable logging or limit it to errors in production environments. This optimizes performance and reduces storage costs.

```objectivec
// Capture errors only
configuration.logLevel = PNErrorLogLevel;

// Disable logging completely
configuration.logLevel = PNNoneLogLevel;
```

### Provide logs to support

When reporting issues to [PubNub support](https://support.pubnub.com/), include complete logs:

1. Set the log level to `PNDebugLogLevel` or `PNTraceLogLevel`.
2. Reproduce the issue.
3. Collect logs from initialization through the problem occurrence.
4. Include the PubNub SDK version. Access the version using `[PubNub information]`.

## Collect device logs and crash reports

Gather crash reports and device logs from the App Store, TestFlight, and directly from devices in addition to PubNub SDK logs.

### Access crash reports and device logs

For comprehensive debugging information, refer to Apple documentation:

* [Diagnosing Issues Using Crash Reports and Device Logs](https://developer.apple.com/documentation/xcode/diagnosing_issues_using_crash_reports_and_device_logs/acquiring_crash_reports_and_diagnostic_logs)
* [Adding Identifiable Symbol Names to a Crash Report](https://developer.apple.com/documentation/xcode/diagnosing_issues_using_crash_reports_and_device_logs/adding_identifiable_symbol_names_to_a_crash_report)

### Retrieve log files from devices

Retrieve log files created by `PNFileLogger` using one of these methods:

| Method | Steps |
| --- | --- |
| Xcode Devices window | Connect the device to your computer. Open Xcode and select Window → Devices and Simulators. Select the device and application. Download the app container. Navigate to the logs directory. The default location is `Documents/PubNubLogs`. |
| Third-party file management tools | Connect the device to your computer. Open a tool such as iExplorer or similar applications. Browse to `YourApp/Documents/PubNubLogs`. Copy the log files to your computer. |
| File Sharing | Enable file sharing in the application Info.plist file. Access the files through iTunes on macOS Mojave or earlier, or through Finder on macOS Catalina and later. |

Include log files in your support tickets to help resolve issues faster.

## Configuration reference

For complete details on all configuration options, see [Configuration API](https://www.pubnub.com/docs/sdks/objective-c/api-reference/configuration).