Browse SDKs · iOS
Platform
SDKsiOS

Logging

Configure OpenIM iOS SDK logs, write application diagnostics, and upload logs.

Copy

OpenIM iOS SDK logging aids in diagnosing initialization, connection, and business API invocation issues. Configure initialization settings to adjust log levels, standard output forwarding, and log storage directories.

Configure logging during initialization

Configure logging options on OIMInitConfig before initializing the SDK:

Parameters

ParameterTypeRequiredDescription
logLevelNSIntegerNoSDK log severity level. Defaults to 6.
isLogStandardOutputBOOLNoWhether to print SDK core logs to standard output.
logFilePathNSString *NoCustom directory path for log file storage. Must be writable by the application sandbox.
systemTypeNSString *NoSystem-type identifier recorded in log headers (e.g., @"ios").

Higher log verbosity generates larger log volumes. Ensure logFilePath references a valid sandbox directory with write permissions.

Code example

OIMInitConfig *config = [OIMInitConfig new];
config.platform = iPhone;
config.apiAddr = apiAddress;
config.wsAddr = websocketAddress;
config.dataDir = dataDirectory;
config.logLevel = 4;
config.isLogStandardOutput = YES;
config.logFilePath = logDirectory;
config.systemType = @"ios";

Write application diagnostic logs

Inject application-specific business context into SDK log streams by calling logs:line:msgs:err:keyAndValues:logLevel::

[[OIMManager manager] logs:[NSString stringWithUTF8String:__FILE__].lastPathComponent
                      line:__LINE__
                      msgs:@"send_message_failed"
                       err:errorMessage
              keyAndValues:@[@"conversationID", conversationID,
                             @"clientMsgID", clientMsgID]
                  logLevel:2];

Pass keyAndValues as alternating key and value pairs to attach diagnostic metadata such as conversationID and clientMsgID.

Upload logs

Upload SDK logs to the remote server for remote troubleshooting:

[[OIMManager manager] uploadLogsWithProgress:^(NSInteger saveBytes, NSInteger currentBytes, NSInteger totalBytes) {
    [self updateLogUploadCurrentBytes:currentBytes totalBytes:totalBytes];
}
                                             line:2000
                                               ex:@"support-ticket-42"
                                        onSuccess:^(NSString * _Nullable data) {
    [self showLogUploadCompleted];
}
                                        onFailure:^(NSInteger code, NSString *message) {
    [self showLogUploadError:code message:message];
}];

The progress closure sequentially delivers saved bytes, currently processed bytes, and total bytes.

Return value

The onSuccess callback indicates that the log upload request completed successfully. If the upload encounters an error, inspect code and message in onFailure to diagnose the failure.