Skip to Content

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 Mobile Services cockpit
flyingfish162Bruce MengMarch 22, 2022
Created by
danielva
October 14, 2018
Contributors
danielva
flyingfish162

Prerequisites

  • Step 1
    1. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and enter EntitySetListActivity to open EntitySetListActivity.java.

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

      Note that the following method contains two LOGGER statements:

      Java
      Copy
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          LOGGER.debug("onOptionsItemSelected: " + item.getTitle());
          switch (item.getItemId()) {
              case R.id.menu_settings:
                  LOGGER.debug("settings screen menu item selected.");
                  this.startActivity(new Intent(this, SettingsActivity.class));
                  return true;
      

      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.

  • Step 2
    1. Navigate to the entity list screen and open the app’s menu.

      Settings menu button
    2. Choose Settings.

      Settings menu opened
    3. Select Log Level.

      Log level settings option
    4. Set the level to Debug.

      Debug log level option
    5. Navigate back to the entity list screen, then back into the Settings screen to see the effect of changing the log level.

      Settings menu opened
    6. Examine the Logcat (located at the bottom of the Android Studio screen, click it and you can see the logs). In the filter, add the name of the class 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.

    1. Change the filter to com.sap.cloud.mobile.foundation.

    2. Press Back to exit the app and you will see 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
    1. Navigate back to the Settings menu in the app, and this time tap Upload Log.

      Upload log button in settings menu

      A Toast message is displayed confirming that the upload succeeded.

      Log upload succeeded
    2. In the Mobile Services cockpit, navigate to Mobile Applications > Native/Hybrid > com.sap.wizapp > Mobile Client Log Upload.

      Mobile Applications > Native/Hybrid > com.sap.wizapp > Mobile Client Log Upload
    3. Select the Logs tab and you will see the log you just uploaded in the list (only the Error level can be viewed here). If the log doesn’t appear immediately, wait for a few moments, then click Go to refresh the view.

      View log
    4. You can inspect the log details in the browser by clicking on its table entry. The following screenshot contains the details of the first log.

      View log details
    5. Select the Log Files tab and you will see the log files you just uploaded in the list. You can download the files by clicking Download.

      View log details
    6. Additionally, you can access the logs locally on an emulator. You can browse the file system of an Android emulator using the Device File Explorer to view the log files as shown below, in data > data > com.sap.wizapp (or the package name of your project) > files.

      View logs in emulator
    7. You can manage the initial log level of the application and the ability for mobile services to accept logs on the Configuration page, as shown below.

      Log Policy

    For further information on logging, see Logging.

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

Back to top