Logging
Configure OpenIM React Native SDK logging, write diagnostic information, and upload logs to the server.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
logFilePath | string | Yes | Local directory for SDK log files, located within the application's writable sandbox. |
logLevel | LogLevel | No | Log output verbosity level: Debug, Info, Warn, Error, Fatal, or Panic. |
isLogStandardOutput | boolean | No | Whether 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
| Parameter | Type | Required | Description |
|---|---|---|---|
logLevel | number | Yes | Log level for this specific entry. |
file | string | Yes | Source file name or module name where the log originated. |
line | number | Yes | Line number in the source file. |
msgs | string | Yes | Brief description of the business action or diagnosis. |
err | string | Yes | Error message string. Pass an empty string "" if no error occurred. |
keyAndValue | string[] | No | Additional 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
| Parameter | Type | Required | Description |
|---|---|---|---|
line | number | Yes | Maximum number of log lines to extract for this upload. |
cancelID | string | No | Unique identifier for the upload task, used to cancel the upload if needed. |
ex | string | No | Additional 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.
Was this page helpful?