Upload Logs from an MDK App
- 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.

- 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.
-
Login to Mobile Services Cockpit, click
com.sap.mdk.demo
| Mobile Client Log Upload. -
Check Log Upload option and click Save.
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.
-
Create a log action of type
SetState
:Right-click the Actions folder | MDK: New Action | choose Log in Category | click Log | Next.
In the Base Information step, provide the below information:
Property Value Name
LogSetState
Type
Select SetState
from the dropdownLoggerState
Select On
from the dropdownClick Finish to create the action creation process.
-
Create a log action of type
SetLevel
:Right-click the Actions folder | MDK: New Action | choose Log in Category | click Log | Next.
In the Base Information step, provide the below information:
Property Value Name
LogSetLevel
Type
Select SetLevel
from the dropdownLevel
Select Trace
from the dropdownClick Finish to create the action creation process.
-
Create a log action of type
Upload
:Right-click the Actions folder | MDK: New Action | choose Log in Category | click Log | Next.
In the Base Information step, provide the below information:
Property Value Name
LogUpload
Type
Select Upload
from the dropdownClick Finish to create the action creation process.
-
- Step 3
In the Project Explorer, click the
LogSetState.action
file | expand Common Action Properties | click the link icon for Success Action and bind it toLogSetLevel.action
- Step 4
When the metadata is downloaded from App Update,
OnDidUpdate
event is being called which eventually triggersInitializeOffline.action
. You can look atApplication.app
file for the details.You will bind
LogSetState.action
at success ofInitializeOffline.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 toLogSetState.action
- Step 5
You will define two message actions for displaying success or failure when Log upload action is triggered.
Expand the Common Action Properties section in the
LogUpload.action
and select theCreate a rule/action
for its Success Action.Keep the default selection for the Object Type as Action and Folders path.
In the Template Selection step, choose Message in Category | click Message | Next.
In the Base Information step, provide the below information:
Property Value Name
LogUploadSuccessful
Type
Select ToastMessage
from the dropdownMessage
Log File Uploaded
NumberOfLines
1 Duration
3 IsIconHidden
Select true
from the dropdownAnimated
Select true
from the dropdownClick Finish to create the action creation process.
Switch back to the
LogUpload.action
tab and create a message action displaying error in case of the Log Upload failure. In theLogUpload.action
, click theCreate a rule/action
icon for the Failure Action.Keep the default selection for the Object Type as Action and Folders path.
In the Template Selection step, choose Message in Category | click Message | Next.
In the Base Information step, provide the below information:
Property Value Name
LogUploadFailure
Type
Select Message
from the dropdownMessage
Failed to upload client logs - {#ActionResults:LogUpload/error}
Title
Upload Client Logs
OKCaption
OK
OnOK
--None--
CancelCaption
leave it blank OnCancel
--None--
Click Finish to create the action creation process.
LogUpload
is the Action Result value of theLogUpload.action
. This reference is used to pass the results to subsequent actions in the chain. These actions can reference the action result as needed. In this case if there is a failure, you access the error property of the action result to display the failure message.Let’s show an Activity Indicator in the MDK client when logs are being uploaded to the SAP Mobile Services. Switch back to the
LogUpload.action
tab and provide below information.Property Value Show Activity Indicator
Select true
from the dropdownActivity Indicator Text
Uploading Logs...
- 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.-
In the
Main.page
, drag and drop an Toolbar Item to the bottom right of the page. -
Provide the below information:
Property Value Caption
Upload Logs
Visible
$(PLT,true,true,false)
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. -
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 theOnPress
Action.
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.
Right-click
Application.app
and select MDK: Deploy.Select deploy target as Mobile Services.
You should see Deploy to Mobile Services successfully! message.
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.
- Step 8
- Step 9
Open SAP Mobile Services Cockpit, click Mobile Applications | Native/MDK | click
com.sap.mdk.demo
app | Mobile Client Log Upload | Log Files.A log file is created for each upload. All the uploaded files, including all levels, not just error or fatal will be listed here.
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?
- Define client log policy in Mobile Services cockpit
- Create log actions
- Bind Set Level log action to the success of Set State action
- Bind Set State log action to success of Initialize Offline action
- Define success/failure messages for Log Upload action
- Add Upload Log button to main page
- Deploy the application
- Run the app
- Examine uploaded logs in Mobile Services cockpit