Browse SDKs · iOS
Platform
SDKsiOS

Logging

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

Copy

OpenIM iOS SDK logs help diagnose initialization, connection, and business API issues. Initialization options control the log level, standard output, and log directory.

Configure logging during initialization

Logging options belong to OIMInitConfig and must be set before initSDKWithConfig:...:

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";

Parameters

FieldTypeDescription
logLevelNSIntegerThe SDK log level. The default is 6.
isLogStandardOutputBOOLWhether to emit standard SDK logs.
logFilePathNSString *Optional directory for log files.
systemTypeNSString *System-type label written into logs.

More detailed levels produce more log output. logFilePath must point to a location writable by the application.

Write application diagnostic logs

To include application context in SDK logs, call:

[[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 key-value pairs to add call context such as conversationID and clientMsgID.

Upload logs

Use the following method to upload SDK logs:

[[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 callback reports saved, currently processed, and total bytes in that order. The success callback means that the upload request completed.