Browse SDKs · React Native
SDKsReact Native

Logging

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

Copy

OpenIM React Native SDK logs help diagnose initialization, connection, and business API problems. Development and staging environments can use more detailed logs. Production should reduce the log level and avoid recording tokens, complete message bodies, raw file URLs, call room credentials, or private user fields.

Configure logging during initialization

Configure the logging options when calling initSDK(). For apiAddr, wsAddr, dataDir, and the initialization and sign-in flow, see Authenticate and manage a session.

await OpenIMSDK.initSDK({
  apiAddr,
  wsAddr,
  dataDir,
  logFilePath,
  logLevel: LogLevel.Debug,
  isLogStandardOutput: true,
});
ParameterTypeDescription
logFilePathstringSDK log directory in an application-writable path.
logLevelLogLevelLog verbosity: Debug, Info, Warn, Error, Fatal, or Panic.
isLogStandardOutputbooleanWhether SDK logs are written to the platform standard log. Enable it for development diagnostics.

Use LogLevel.Debug for development diagnostics. Production applications usually use LogLevel.Warn or LogLevel.Error and disable unnecessary standard output.

Write application logs

Call logs() to write business diagnostic information to the SDK log:

await OpenIMSDK.logs({
  logLevel: LogLevel.Error,
  file: 'chatRepository.ts',
  line: 184,
  msgs: 'send_message_failed',
  err: error.message,
  keyAndValue: [
    'conversationID',
    conversationID,
    'clientMsgID',
    clientMsgID,
  ],
});
ParameterTypeDescription
logLevelnumberLog level for this entry.
filestringFile or module name at the call site.
linenumberLine number at the call site.
msgsstringShort business action or diagnostic description.
errstringError information; pass an empty string when there is no error.
keyAndValuestring[]Additional diagnostic fields passed as key and value pairs.

Use keyAndValue only for non-sensitive identifiers needed for diagnosis, such as conversationID, clientMsgID, groupID, or roomID.

Upload logs

When a user actively submits diagnostic logs, call uploadLogs() to upload the client logs:

await OpenIMSDK.uploadLogs({
  line: 2000,
  cancelID: 'support-ticket-42',
  ex: 'user-initiated-diagnostics',
});
ParameterTypeRequiredDescription
linenumberYesNumber of log lines to read for this upload.
cancelIDstringNoIdentifier for this upload.
exstringNoAdditional diagnostic description; it must not contain credentials or private data.

When the call returns, the log upload request has completed. Before uploading, explain the log collection scope to the user and follow privacy and compliance requirements.