Logging
Configure Android SDK logging, write application logs, and upload logs.
OpenIM Android SDK logs help diagnose initialization, connection, and business API problems. Initialization options control the log level, standard output, and log directory.
Configure logging during initialization
Configure logging when calling initSDK():
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 | Controls verbosity with a LogLevel constant. Available values include DebugWithSQL, Debug, Info, Warn, Error, Panic, and Fatal. |
isLogStandardOutput | Writes SDK logs to Android standard output when enabled. |
logFilePath | Optional log directory, which must be writable by the application. |
DebugWithSQL includes database diagnostic details. Debug, Info, Warn, and Error progressively reduce the amount of output. Select the level that matches the current diagnostic scope.
Write application logs
Use logs() to write application logs to the SDK log:
OpenIMClient.getInstance().logs(
LogLevel.Error,
ChatRepository.class.getSimpleName(),
184,
"send_message_failed",
errorMessage,
"conversationID", conversationID,
"clientMsgID", clientMsgID
);currentClassName and currentLineNum identify the call site. msgStr is a short action description, and errStr is the error information. Warn, Error, Panic, and Fatal require a non-empty error string. Pass trailing extra values as key-value pairs.
The older logs() overload with OnBase<String> and Map parameters is deprecated and should not be used in new code.
Upload logs
Use uploadLogs() to upload client logs to the server, primarily when a user actively submits diagnostic logs.
String cancelID = UUID.randomUUID().toString();
OpenIMClient.getInstance().uploadLogs(
new OnBase<String>() {
@Override
public void onSuccess(String data) {
// The log upload request completed.
}
@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 indicate upload progress.
}
}
);| Parameter | Description |
|---|---|
params | Legacy parameter that the current SDK does not use. Pass an empty list, such as new ArrayList<>(). |
line | Number of log lines configured for this upload. |
cancelID | Stable identifier for this upload, such as an application-generated UUID. |
ex | Context attached to the upload task, such as a support ticket ID. |
UploadLogProgress | Reports current progress and total work for the upload interface. |
The success callback means that the log upload request completed.
After the upload completes, use the occurrence time, action name, and relevant conversationID, clientMsgID, groupID, or roomID to locate the corresponding call.
Related pages
Was this page helpful?