SDKsiOS
日志
配置 OpenIM iOS SDK 日志,写入应用诊断信息并上传日志。
OpenIM iOS SDK 的日志用于定位初始化、连接和业务 API 调用问题。初始化配置可以控制日志级别、标准输出和日志目录。
初始化日志配置
日志选项属于 OIMInitConfig,必须在 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";参数说明
| 字段 | 类型 | 说明 |
|---|---|---|
logLevel | NSInteger | SDK 日志级别,默认值为 6。 |
isLogStandardOutput | BOOL | 是否输出 SDK 标准日志。 |
logFilePath | NSString * | 可选的日志文件目录。 |
systemType | NSString * | 日志中的系统类型标识。 |
日志级别越详细,产生的日志内容越多。logFilePath 需要指向应用可写目录。
写入应用诊断日志
需要把应用业务上下文写入 SDK 日志时,可调用:
[[OIMManager manager] logs:[NSString stringWithUTF8String:__FILE__].lastPathComponent
line:__LINE__
msgs:@"send_message_failed"
err:errorMessage
keyAndValues:@[@"conversationID", conversationID,
@"clientMsgID", clientMsgID]
logLevel:2];keyAndValues 按“键、值”成对传入,可用于补充 conversationID、clientMsgID 等调用上下文。
上传日志
调用以下方法可以上传 SDK 日志:
[[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];
}];上传进度 callback 依次提供已保存、当前处理和总字节数。成功 callback 表示本次上传请求已完成。
这个页面有帮助吗?