Logger
Configure OpenIM Flutter SDK logging, write diagnostic entries, and upload logs to the server.
The OpenIM Flutter SDK logging system assists in diagnosing SDK initialization issues, WebSocket connection errors, and business API failures. Configure the log level, standard output, and custom log file path during SDK initialization. You can also write application diagnostic entries into the SDK log buffer and upload local logs to the server on demand.
Initialize logging configuration
Configure the logging strategy during SDK initialization rather than at sign-in time.
Parameters
Specify the following logging parameters when calling initSDK:
| Parameter | Type | Required | Description |
|---|---|---|---|
logLevel | int | No | Numeric SDK logging level. Lower numbers generate more detailed logs. Defaults to 6. |
isLogStandardOutput | bool | No | Whether to print logs synchronously to the system console or debug terminal. |
logFilePath | String? | No | Custom local file path for storing logs. Must reside in a writable application sandbox directory on the target platform. |
Code example
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,
);Pass IMPlatform.android when running on Android and IMPlatform.ios on iOS.
Write custom diagnostic logs
Record critical business exceptions or debug traces directly into the SDK's local log system so that application events correlate with underlying SDK diagnostics:
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
logLevel | int | No | Numeric log level for this entry. |
file | String | Yes | File name or module identifier where the log is generated. |
line | int | Yes | Source line number triggering the log. |
msgs | String | Yes | Main descriptive log message. |
err | String? | No | Caught error string or stack trace. |
keyAndValues | List<dynamic>? | No | Structured key-value pairs arranged alternately (for example, ['key1', 'val1']). |
Code example
await OpenIM.iMManager.logs(
logLevel: 5,
file: 'chat_repository.dart',
line: 120,
msgs: 'load conversation page failed',
err: error.toString(),
keyAndValues: ['conversationID', conversationID],
);Return value
A successful Future returns void, indicating that the log entry has been written to the local log buffer.
Listen and upload logs
When a user initiates feedback or when remote troubleshooting is required, upload the local log files to the server:
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ex | String? | No | Reason for uploading or supplementary business diagnostic remarks. |
Code example
OpenIM.iMManager.setUploadLogsListener(
OnUploadLogsListener(
onUploadProgress: (current, size) {
updateLogUploadProgress(current, size);
},
),
);
await OpenIM.iMManager.uploadLogs(ex: 'user initiated diagnostics');Return value
A successful Future returns void, indicating that the log upload operation was initiated and completed the transfer.
The SDK maintains a single OnUploadLogsListener instance; setting a new listener overwrites the previous one. Register this listener once within a centralized diagnostics service and dispatch progress to UI components. Clear pending upload tasks when switching accounts.
Was this page helpful?