Logging
Configure OpenIM Android SDK logging, record application diagnostic events, and upload logs for debugging.
OpenIM Android SDK logging helps diagnose initialization issues, connection drops, and API failures. You can customize the log level, standard output redirection, and log directory within your initialization configuration.
Configure logging on initialization
Configure logging options when initializing the SDK:
File dataDirectory = new File(application.getFilesDir(), "openim");
File logDirectory = new File(application.getFilesDir(), "openim-logs");
InitConfig config = new InitConfig(
apiAddr,
wsAddr,
dataDirectory.getAbsolutePath()
);
config.logLevel = BuildConfig.DEBUG ? LogLevel.Debug : LogLevel.Warn;
config.isLogStandardOutput = BuildConfig.DEBUG;
config.logFilePath = logDirectory.getAbsolutePath();
boolean initialized = OpenIMClient.getInstance().initSDK(
application,
config,
connectionListener
);| Field | Description |
|---|---|
logLevel | Uses LogLevel constants to control verbosity. Options include DebugWithSQL, Debug, Info, Warn, Error, Panic, and Fatal. |
isLogStandardOutput | Determines whether the SDK prints log output to Android logcat. |
logFilePath | Optional log storage directory, which must reside within writable application storage. |
DebugWithSQL captures raw SQLite execution details, whereas Debug, Info, Warn, and Error successively reduce output volume. Select an appropriate logging level according to your troubleshooting requirements.
Write application logs
When you need to persist application-level diagnostics alongside SDK events in local log files, call logs():
OpenIMClient.getInstance().logs(
LogLevel.Error,
ChatRepository.class.getSimpleName(),
184,
"send_message_failed",
errorMessage,
"conversationID", conversationID,
"clientMsgID", clientMsgID
);currentClassName and currentLineNum locate the call site, msgStr provides an action description, and errStr contains the failure details. Levels Warn, Error, Panic, and Fatal require a non-empty errStr. Key-value attributes at the end are passed in trailing alternating pairs.
Legacy overloads that accepted callback listeners or Map parameters are deprecated; use the varargs signature above.
Upload logs
When users report unexpected behavior or customer support requests diagnostics, upload client log files to the server:
String cancelID = UUID.randomUUID().toString();
OpenIMClient.getInstance().uploadLogs(
new OnBase<String>() {
@Override
public void onSuccess(String data) {
// Log upload request completed successfully.
}
@Override
public void onError(int code, String error) {
// code and error describe the failure.
}
},
new ArrayList<>(),
2000, // line
cancelID,
"support-ticket-42", // ex
new UploadLogProgress() {
@Override
public void onProgress(long current, long total) {
// current and total report upload progress.
}
}
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<String> | Yes | Callback delivering the final upload status. |
params | List<String> | No | Legacy parameter unused by the current SDK; pass an empty list, such as new ArrayList<>(). |
line | int | Yes | Number of log lines to extract and upload. |
cancelID | String | Yes | Unique task identifier for this upload session, such as a random UUID. |
ex | String | No | Business metadata attached to the upload task, such as a support ticket ID. |
UploadLogProgress | UploadLogProgress | No | Progress listener reporting uploaded and total byte counters. |
Return value
The successful callback indicates that the log package has been uploaded to the server. You can cross-reference the upload with timestamps, operation names, and identifiers such as conversationID, clientMsgID, groupID, or roomID to trace issues.
Related guides
Was this page helpful?