Skip to Content

Upload Logs from an MDK App

test
0 %
Upload Logs from an MDK App
Details

Upload Logs from an MDK App

September 10, 2020
Created by
May 24, 2019
Allow users to upload logs from an MDK app to SAP Cloud Platform 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

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


MDK
Step 1: Define client log policy in Mobile Services cockpit

SAP Cloud Platform 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 Cloud Platform 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.

Log on to answer question
Step 2: Create log actions

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. Next.

    MDK

    Provide the below information:

    Property Value
    Action Name LogSetState
    Type Select SetState from the dropdown
    LoggerState Select 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. Next.

    Provide the below information:

    Property Value
    Action Name LogSetLevel
    Type Select SetLevel from the dropdown
    Level Select Debug from the dropdown

    Setting log level to debug is not recommended for productive environment.

    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. Next.

    Provide the below information:

    Property Value
    Action Name LogUpload
    Type Select Upload from the dropdown
    MDK

    Click Next and then Finish on the confirmation step.

Log on to answer question
Step 3: Bind Set Level log action to the success of Set State action

Double click the LogSetState.action file | expand Common Action Properties and select LogSetLevel.action for Success Action.

MDK
Log on to answer question
Step 4: Bind Set State log action to success of InitializeOffline action

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, select LogSetState.action for the Success Action.

MDK
Log on to answer question
Step 5: Define success/failure messages for Log Upload action

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 Name LogUploadSuccessful
    Type Select ToastMessage from the dropdown
    Message Log File Uploaded
    MaxNumberOfLines 1
    Duration 3
    IsIconHidden Select 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 Name LogUploadFailure
    Type Select Message from the dropdown
    Message Uploading log file failed
    Title Log 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 Action Select LogUploadSuccessful.action from the dropdown
    Failure Action Select LogUploadFailure.action from the dropdown
    Show Activity Indicator Select true from the dropdown
    Activity Indicator Text Uploading Logs...
    MDK
Log on to answer question
Step 6: Add Upload Log button to main page

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. Replace Caption to Upload Logs.

    MDK
  3. In the Properties pane, click the Events tab, click the link 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
Log on to answer question
Step 7: Deploy and activate the application

Deploy the updated application to your MDK client.

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

MDK

You should see Deploy Succeeded message.

MDK
Log on to answer question
Step 8: Test the application
  1. Re-launch the app on your device, you may asked to authenticate with passcode or Fingerprint. You will see a Confirmation pop-up, tap OK.

    At OnLaunch event, app starts gathering logs.

  2. Tap UPLOAD LOGS to upload client logs from app to SAP Cloud Platform Mobile Services.

    MDKMDK
  1. Re-launch the app on your device, you may asked to authenticate with passcode or Touch ID. You will see a Confirmation pop-up, tap OK.

    At OnLaunch event, app starts gathering logs.

  2. Tap Upload Logs to upload client logs from app to SAP Cloud Platform Mobile Services.

    MDKMDK
Log on to answer question
Step 9: Examine uploaded logs in Mobile Services cockpit

Open SAP Cloud Platform Mobile Services Cockpit, click Mobile Applications | Native/Hybrid | click MDK app | Mobile Client Log Upload | Logs.

MDK

You may view log entries directly in Mobile Services Cockpit or download them locally.

You can find more details about Uploading and Viewing Client Logs.

Congratulations! You have successfully uploaded client logs to SAP Cloud Platform Mobile Services and you are now all set to Extend an MDK App with Customer Orders.

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

Next Steps

Back to top