Browse SDKs · Flutter
Platform
SDKsFlutter

Logger

Configure OpenIM Flutter SDK logging, write diagnostic entries, and upload logs to the server.

Copy

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:

ParameterTypeRequiredDescription
logLevelintNoNumeric SDK logging level. Lower numbers generate more detailed logs. Defaults to 6.
isLogStandardOutputboolNoWhether to print logs synchronously to the system console or debug terminal.
logFilePathString?NoCustom 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

ParameterTypeRequiredDescription
logLevelintNoNumeric log level for this entry.
fileStringYesFile name or module identifier where the log is generated.
lineintYesSource line number triggering the log.
msgsStringYesMain descriptive log message.
errString?NoCaught error string or stack trace.
keyAndValuesList<dynamic>?NoStructured 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

ParameterTypeRequiredDescription
exString?NoReason 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.