Skip to Content

See How Logging Can Be Used in Your Android Application

0 %
See How Logging Can Be Used in Your Android Application

See How Logging Can Be Used in Your Android Application

Explore how the logging component can help make deployed applications more supportable.

You will learn

  • How to use the Logging component to log messages
  • How to change the log level
  • How to upload and view logs in the SAP Cloud Platform Mobile Services cockpit

Step 1: Use the logging component

In Android Studio, on Windows press Control+N or on a Mac press command+O and enter EntitySetListActivity to open

On Windows press Ctrl+F12 or on a Mac press command+F12 and enter onOptionsItemSelected to move to the onOptionsItemSelected method.

Note that below method contains two LOGGER statements:

public boolean onOptionsItemSelected(MenuItem item) {
    LOGGER.debug("onOptionsItemSelected: " + item.getTitle());
    switch (item.getItemId()) {
            LOGGER.debug("settings screen menu item selected.");
            Intent intent = new Intent(this, SettingsActivity.class);
            this.startActivityForResult(intent, SETTINGS_SCREEN_ITEM);
            return true;

		        return false;

These messages will be logged when the app’s log level is set to Debug or Path and the app’s Settings menu item is opened.

Log on to answer question
Step 2: Change the log level

Navigate to the entity list screen and open the app’s menu.

Settings menu button

Choose Settings.

Settings menu opened

Select Log Level.

Log level settings option

Set the level to Debug.

Debug log level option

Navigate back to the entity list screen, then back into the settings screen to show the effect of changing the log level.

Settings menu opened

Examine the Logcat. In the filter add the class name that we are interested in seeing the log from.

Notice that the messages were logged since the log level of the app was set to DEBUG or PATH.

Debug log level output

The SDK libraries also log output based on the app’s log level.

Change the filter to

Press the back button to exit the app and notice the logged lines from the foundation library.

Debug log level output for foundation
If the application's log level is set to Info, which of the following would be logged?
Step 3: Upload and view the log

Navigate back to the settings menu in the app, and this time, tap the “Upload Log” button.

Upload log button in settings menu

A Toast message will appear, confirming the upload succeeded.

Log upload succeeded

In the Mobile Services cockpit, navigate to Analytics > Logs > Technical Logs.

Analytics > Logs > Technical Logs

You should be able to see the log you just uploaded in the list of technical logs. You can inspect the log in browser by clicking on its table entry, or you can download the text version by selecting it and clicking the download button. If the log doesn’t appear immediately, wait for a few moments then click “Go” to refresh the view.

View log

Additionally, you can access the logs locally on an emulator. The file system of an Android emulator can be browsed using the Device File Explorer to view the log files as shown below, in /data/user/0/

View logs in emulator

The initial log level of the application and the ability for Mobile Services to accept logs can be managed in the Client Policies feature as shown below.

Log Policy

The log level of a an individual registration can also be set in the Management Cockpit as shown below.

User RegistrationsUser Registration Log Settings

Further information on logging can be found at Logging.

Congratulations! You have explored how the logging feature can be used to debug or support a deployed application.

Log on to answer question

Next Steps

Back to top