Skip to content

Uploading Logs

The SAP BTP SDK for Android version 4.0 introduces a simplified LoggingService to manage all logging-related tasks. As a result, the Logging API is now deprecated.

The log upload API in LoggingService is:

fun upload(
    owner: LifecycleOwner? = null,
    uploadType: LogUploadType? = null,
    listener: ServiceListener<Boolean>? = null,
    progressReporter: ((Int) -> Unit)? = null
    )

All the arguments can be null, meaning that the client code does not have to care about upload progress, nor the result. To observe the result, both owner and listener must be provided. The owner could be an activity or a fragment that has a lifecycle. The activity or fragment is destroyed by the Android system, and the listener will also be removed automatically to avoid wasting system resources.

Sample client code:

SDKInitializer.getService(LoggingService::class)?.also { logging ->
    logging.upload(owner = this, listener = object : ServiceListener<Boolean> {
        override fun onServiceDone(result: ServiceResult<Boolean>) {
            val msg = if (result is ServiceResult.SUCCESS) {
                getString(R.string.log_upload_done)
            } else {
                (result as ServiceResult.FAILURE).message
            }
            Toast.makeText(this@MainBusinessActivity, msg, Toast.LENGTH_LONG).show()
        }
    }) {
        //the upload progress reporter
        logger.debug("Log uploaded $it%")
    }
}

Upload Type

You can control what happens to the temporary store when you upload the log by setting the uploadType parameter of the upload API. The types are:

  • LogUploadType.DEFAULT: Upload the current content of the logs. If there is an old log that did not get uploaded from a previous upload attempt, the old log is deleted and not uploaded.

  • LogUploadType.LAST: If there is an old log that did not get uploaded from a previous upload attempt, upload the old log but do not upload the current content of the logs.

  • LogUploadType.MERGE: Upload the current content of the logs, and if there is an old log that did not get uploaded from a previous upload attempt, also upload the old log. You should be careful with this choice: if repeated attempts to upload the log with this upload type fail, the application could use a lot of storage space.

Automatic Upload

Instead of calling upload explicitly, you can let LoggingService upload logs automatically in the background by setting the autoUpload property. This is controlled by two properties:

  • autoUpload: Whether logs are uploaded automatically. When true, logs are uploaded in the background without any explicit call to upload. Automatic uploads are triggered when a client policy is retrieved and when a log file rolls over due to reaching its size limit. Automatic uploads only run when log upload is enabled by the active policy; otherwise, they are skipped. Defaults to false, meaning logs are uploaded only when you explicitly call upload.

  • autoUploadType: The LogUploadType used for automatic uploads when autoUpload is true. Defaults to LogUploadType.DEFAULT.

You can set these values when constructing the service or modify them later. Changing either value after the service is initialized re-configures the logging service.

// Enable auto upload when constructing the service
val loggingService = LoggingService(autoUpload = true, autoUploadType = LogUploadType.MERGE)

// Or change it later on an existing service
SDKInitializer.getService(LoggingService::class)?.also { logging ->
    logging.autoUpload = true
    logging.autoUploadType = LogUploadType.DEFAULT
}

Automatic uploads run through WorkManager, so they respect the configured network policy and are retried with exponential backoff if they fail.

Configuring Logging

Logging must be configured in the SAP mobile service cockpit to accept log upload:

  1. Add Mobile Client Log Upload feature to the mobile application.
  2. In the Configuration tab of the feature, enable the Log Upload checkbox.

See Defining Client Log Policy for more information.

To view the logs in the SAP mobile service cockpit, go to Log Files tab of the feature, then select the log from the list. You may have to adjust the time range filter to see your log.


Last update: July 23, 2026