Browse SDKs · Android
SDKsAndroid

Logging

Configure Android SDK logging, write application logs, and upload logs.

Copy

OpenIM Android SDK logs help diagnose initialization, connection, and business API problems. Development and staging builds can use more detailed output. Production builds should reduce log volume and must avoid recording tokens, complete message bodies, raw file URLs, call room credentials, and private user fields.

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
);
FieldDescription
logLevelControls verbosity with a LogLevel constant. Available values include DebugWithSQL, Debug, Info, Warn, Error, Panic, and Fatal.
isLogStandardOutputWrites SDK logs to Android standard output when enabled; use it for development diagnostics.
logFilePathOptional log directory. Keep it within application-writable storage and manage its size and retention.

Use Debug for ordinary development diagnostics. Enable DebugWithSQL temporarily and only when diagnosing database problems. Production builds normally use Warn or Error and disable unnecessary standard output.

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 and include only non-sensitive identifiers needed for diagnosis.

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.
        }
    }
);
ParameterDescription
paramsLegacy parameter that the current SDK does not use. Pass an empty list, such as new ArrayList<>().
lineNumber of log lines configured for this upload.
cancelIDStable identifier for this upload, such as an application-generated UUID.
exDiagnostic context attached to the task, such as a support ticket ID. It must not contain credentials or private data.
UploadLogProgressReports current progress and total work for the upload interface.

The success callback means that the log upload request completed.

When investigating a problem or providing logs to support, include the time of the issue, user ID, action name, and any relevant conversationID, clientMsgID, groupID, or roomID. These non-sensitive business identifiers help locate the relevant records but do not replace the complete logs.