Browse SDKs · React Native
Platform
SDKsReact Native

Logging

Configure OpenIM React Native SDK logging, write diagnostic information, and upload logs to the server.

Copy

OpenIM React Native SDK logs help troubleshoot initialization, connection, and business API issues. Development and staging environments can use verbose logs. Production applications should lower the log level and avoid recording tokens, full message content, raw file URLs, call room credentials, or sensitive user fields.

Configure logging during initialization

Configure logging options when invoking the SDK initialization method. For complete details on server endpoints, storage paths, and the sign-in workflow, see Authenticate and manage a session.

await OpenIMSDK.initSDK({
  apiAddr,
  wsAddr,
  dataDir,
  logFilePath,
  logLevel: LogLevel.Debug,
  isLogStandardOutput: true,
});

Parameters

ParameterTypeRequiredDescription
logFilePathstringYesLocal directory for SDK log files, located within the application's writable sandbox.
logLevelLogLevelNoLog output verbosity level: Debug, Info, Warn, Error, Fatal, or Panic.
isLogStandardOutputbooleanNoWhether to print underlying SDK logs to the system console. Recommended during development.

Use LogLevel.Debug in development and testing environments. Set logLevel to LogLevel.Warn or LogLevel.Error in production, and disable standard console output to optimize performance.

Write application logs

Append application-level diagnostic information directly to the SDK logging pipeline to facilitate unified log extraction and troubleshooting:

await OpenIMSDK.logs({
  logLevel: LogLevel.Error,
  file: 'chatRepository.ts',
  line: 184,
  msgs: 'send_message_failed',
  err: error.message,
  keyAndValue: [
    'conversationID',
    conversationID,
    'clientMsgID',
    clientMsgID,
  ],
});

Parameters

ParameterTypeRequiredDescription
logLevelnumberYesLog level for this specific entry.
filestringYesSource file name or module name where the log originated.
linenumberYesLine number in the source file.
msgsstringYesBrief description of the business action or diagnosis.
errstringYesError message string. Pass an empty string "" if no error occurred.
keyAndValuestring[]NoAdditional diagnostic key-value pairs passed as paired entries: [key1, val1, key2, val2].

Use keyAndValue only for necessary troubleshooting identifiers (such as conversationID, clientMsgID, or groupID). Never record sensitive credentials such as tokens or plaintext passwords.

Upload logs

When a user encounters an issue or triggers an in-app "Report Log" diagnostic action, call this method to package client logs and upload them to the server:

await OpenIMSDK.uploadLogs({
  line: 2000,
  cancelID: 'support-ticket-42',
  ex: 'user-initiated-diagnostics',
});

Parameters

ParameterTypeRequiredDescription
linenumberYesMaximum number of log lines to extract for this upload.
cancelIDstringNoUnique identifier for the upload task, used to cancel the upload if needed.
exstringNoAdditional business diagnostic notes. Do not include sensitive data.

Return value

A successful Promise resolution indicates that the log upload task was submitted and processed by the server. Prior to uploading, inform the user about the scope of data collected and ensure compliance with relevant privacy regulations.