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.

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: February 29, 2024