Skip to Content

Upload Logs from an MDK App

Allow users to upload logs from an MDK app to SAP Mobile Services.
You will learn
  • How to enable log upload feature in Mobile Services
  • How to upload logs from the app
  • How to examine log details for troubleshooting
jitendrakansalJitendra KansalJuly 8, 2022
Created by
jitendrakansal
May 24, 2019
Contributors
jitendrakansal
jitendrakansal
jitendrakansal

You may clone an existing project from GitHub repository to start with this tutorial.

MDK
  • Step 1

    SAP Mobile Services provides administrators, developers and support staff with extensive logs and traces functionality to troubleshoot application issues. You can control the amount of information that is captured by setting the log level for individual logging components.

    In this step, you will enable client log upload policy in SAP Mobile Services Cockpit for a given MDK app.

    1. Login to Mobile Services Cockpit, click com.sap.mdk.demo | Mobile Client Log Upload.

      MDK
    2. Check Log Upload option and click Save.

      MDK

      Other policy parameters like Log Level, Delete Uploaded Log After, Maximum Number of Logs and Maximum Log Size currently have no effect.

      You can find more details about Client Log Upload feature.

  • Step 2

    Logs help you trace events that occur while your application is running. You can create logging actions, set their priority levels and upload stored log entries.

    You will create 3 actions:

    • Log action of Type SetState: to turn the logger On, Off or Toggle

    • Log action of Type SetLevel: to set log level (Debug, Info, Warn or Error)

    • Log action of Type Upload: to upload logs from app to Mobile Services

    You can find more details about MDK Log Actions.

    MDK
    1. Create a log action of type SetState:

      Right-click the Actions folder | MDK: New Action | choose MDK Log Actions in Category | click Log Action | Next.

      MDK

      Provide the below information:

      Property Value
      Action NameLogSetState
      Type Select SetState from the dropdown
      LoggerStateSelect On from the dropdown
      MDK

      Click Next and then Finish on the confirmation step.

    2. Create a log action of type SetLevel:

      Right-click the Actions folder | MDK: New Action | choose MDK Log Actions in Category | click Log Action | Next.

      Provide the below information:

      Property Value
      Action NameLogSetLevel
      Type Select SetLevel from the dropdown
      LevelSelect Trace from the dropdown
      MDK

      Click Next and then Finish on the confirmation step.

    3. Create a log action of type Upload:

      Right-click the Actions folder | MDK: New Action | choose MDK Log Actions in Category | click Log Action | Next.

      Provide the below information:

      Property Value
      Action NameLogUpload
      Type Select Upload from the dropdown
      MDK

      Click Next and then Finish on the confirmation step.

  • Step 3

    Double click the LogSetState.action file | expand Common Action Properties | click the link icon for Success Action and bind it to LogSetLevel.action

    MDK
  • Step 4

    When the metadata is downloaded from App Update, OnDidUpdate event is being called which eventually triggers InitializeOffline.action. You can look at Application.app file for the details.

    You will bind LogSetState.action at success of InitializeOffline.action.

    Navigate to DemoSampleApp | Actions | Service | InitializeOffline.action | scroll-down and expand Common Action Properties section | click the link icon for Success Action and bind it to LogSetState.action

    MDK
  • Step 5

    You will define two message actions for displaying success or failure when Log upload action is triggered. Later, you will bind these actions in Common Action Properties of LogUpload.action.

    1. You will create a success message action.

      Right-click the Actions folder | MDK: New Action | choose MDK Message Actions in Category | click Message Action | Next.

      Provide the below information:

      Property Value
      Action NameLogUploadSuccessful
      Type Select ToastMessage from the dropdown
      MessageLog File Uploaded
      NumberOfLines1
      Duration 3
      IsIconHiddenSelect true from the dropdown
      Animated Select true from the dropdown
      MDK

      Click Next and then Finish on the confirmation step.

    2. Create a failure message action.

      Right-click the Actions folder | MDK: New Action | choose MDK Message Actions in Category | click Message Action | Next.

      Provide the below information:

      Property Value
      Action NameLogUploadFailure
      Type Select Message from the dropdown
      MessageUploading log file failed
      TitleLog Upload Failed
      OKCaption OK
      OnOK --None--
      CancelCaption leave it blank
      OnCancel --None--
      MDK

      Click Next and then Finish on the confirmation step.

    3. Bind both actions in Common Action Properties of LogUpload.action.

      Double click the LogUpload.action and provide the below information:

      Property Value
      Success ActionClick the link icon and bind it to LogUploadSuccessful.action
      Failure ActionClick the link icon and bind it to LogUploadFailure.action
      Show Activity Indicator Select true from the dropdown
      Activity Indicator TextUploading Logs...
      MDK
  • Step 6

    You will add a toolbar item to the main page called Upload Logs. You will link toolbar item to LogUpload.action you just created in step 2.

    1. In Main page, drag and drop an Toolbar Item to the bottom right of the page.

      MDK
    2. Provide the below information:

      Property Value
      CaptionUpload Logs
      Visible$(PLT,true,true,false)
      MDK

      Platform (PLT) function $(PLT, <iOS>, <Android>, <Web>) lets you to define a platform specific value for metadata property as Upload Logs functionality is not applicable in MDK Web environment, this option will not be visible in Web application. You can find more details on PLT function in help documentation.

    3. In the Properties pane, click the Events tab, click the 3 dots icon for the OnPress property to open the Object Browser.

      Double click the LogUpload.action action and click OK to set it as the OnPress Action.

      MDK

    What is the Visible property set for "Upload Logs" toolbar item in the Main.page for MDK Web environment?

  • Step 7

    Deploy the updated application to your MDK client.

    1. Right-click Application.app and select MDK: Deploy.

      MDK
    2. Select deploy target as Mobile Services.

      MDK

      You should see Deploy to Mobile Services successfully! message.

      MDK

      Alternatively, you can select MDK: Redeploy in the command palette (View menu>Find Command OR press Command+Shift+p on Mac OR press Ctrl+Shift+P on Windows machine), it will perform the last deployment.

      MDK
  • Step 8
  • Step 9

    Open SAP Mobile Services Cockpit, click Mobile Applications | Native/Hybrid | click com.sap.mdk.demo app | Mobile Client Log Upload | Log Files.

    MDK

    A log file is created for each upload. All the uploaded files, including all levels, not just error or fatal will be listed here.

    You can view any Error and Fatal client logs under Logs tab.

    MDK

    Check documentation for more details about Uploading and Viewing Client Logs.

    Which feature of SAP Mobile Services collects and displays log information collected on the device?

Back to top