Browse SDKs · Android
Platform
SDKsAndroid

Logging

Configure OpenIM Android SDK logging, record application diagnostic events, and upload logs for debugging.

Copy

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
);
FieldDescription
logLevelUses LogLevel constants to control verbosity. Options include DebugWithSQL, Debug, Info, Warn, Error, Panic, and Fatal.
isLogStandardOutputDetermines whether the SDK prints log output to Android logcat.
logFilePathOptional 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

ParameterTypeRequiredDescription
baseOnBase<String>YesCallback delivering the final upload status.
paramsList<String>NoLegacy parameter unused by the current SDK; pass an empty list, such as new ArrayList<>().
lineintYesNumber of log lines to extract and upload.
cancelIDStringYesUnique task identifier for this upload session, such as a random UUID.
exStringNoBusiness metadata attached to the upload task, such as a support ticket ID.
UploadLogProgressUploadLogProgressNoProgress 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.