Logging
Configure OpenIM Flutter SDK logs, write application diagnostics, and upload logs.
OpenIM Flutter SDK logs help diagnose initialization, connection, and business API issues. Initialization parameters control the log level, standard output, and log file path.
Configure logging during initialization
The Flutter SDK configures logging in initSDK(), not in login().
import 'dart:io';
final platformID = Platform.isIOS
? IMPlatform.ios
: IMPlatform.android;
await OpenIM.iMManager.initSDK(
platformID: platformID,
apiAddr: apiAddr,
wsAddr: wsAddr,
dataDir: dataDir,
listener: connectListener,
logLevel: 5,
isLogStandardOutput: true,
logFilePath: logFilePath,
);This example targets Flutter on Android and iOS. Use IMPlatform.android on Android and IMPlatform.ios on iOS; do not hard-code the Android value into an iOS build.
| Parameter | Description |
|---|---|
logLevel | Numeric SDK log level. The default is 6. |
isLogStandardOutput | Whether to write to platform-standard logs. |
logFilePath | Optional log-file path in a directory writable by the application. |
More detailed levels produce more log output. Log directories are subject to platform file permissions and lifecycle rules.
Write and upload logs
await OpenIM.iMManager.logs(
logLevel: 5,
file: 'chat_repository.dart',
line: 120,
msgs: 'load conversation page failed',
err: error.toString(),
keyAndValues: ['conversationID', conversationID],
);Listen for upload progress and call uploadLogs():
OpenIM.iMManager.setUploadLogsListener(
OnUploadLogsListener(
onUploadProgress: (current, size) {
updateLogUploadProgress(current, size);
},
),
);
await OpenIM.iMManager.uploadLogs(ex: 'user initiated diagnostics');setUploadLogsListener() stores a manager-level singleton listener, so a later call replaces the earlier one. The SDK does not expose a remove or unset API. Configure it once in the application's shared SDK binding layer and dispatch progress from there to the active UI. On account switch, clear application-level subscriptions and the previous account's upload state.
A successful uploadLogs() Future means that the upload request completed.
Was this page helpful?