Skip to Content
test
0 %
See How Logging Can Be Used in Your Android Application
Details
// Explore More Tutorials

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 EntitySetListActivity.java.

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:

@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		LOGGER.debug("onOptionsItemSelected: " + item.getTitle());
		if (item.getItemId() == SETTINGS_SCREEN_ITEM) {
			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 message will be logged when the app’s log level is set to Debug or Path and the app’s Settings menu item is clicked.

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.

com.sap.wizapp.mdui.EntitySetListActivity

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 com.sap.cloud.mobile.foundation.

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/com.sap.wizapp/files.

View logs in emulator

Note: For more details on logging, check out the Logging.

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

The blog series Step by Step with the SAP Cloud Platform SDK for Android may also be of interest.

Log on to answer question

Next Steps

Back to top