The settings plugin is used to exchange settings between the SMP 3.0 server and a Kapsel application. To demonstrate this, the settings plugin will be added to the Logger Sample and will enable the changing of the log level of the Kapsel app by making changes to the log settings from within the management cockpit. It also automatically uploads the log file to the SMP 3.0 server each time that app starts or resumes if the option to Log Upload is checked on the Client Logging dialog of a registration.
or the JS Documentation at Kapsel Settings API Reference.
The following steps will demonstrate this plugin.
- Change directory to LoggerDemo
cd C:\Kapsel_Projects\LoggerDemo cd ~/Documents/Kapsel_Projects/LoggerDemo
- Add the settings plugin to the LoggerDemo app.
cordova -d plugin add com.sap.mp.cordova.plugins.settings
- Copy the files to the platform directory by running
cordova -d prepare
- After adding the settings plugin, an exchange will occur each time that the application opens (not on a resume). During the settings exchange the log level specified for the application instance or registration and the log upload setting as set in the Management Cockpit is sent to the device. The settings plugin then acts on those values and sets the log level and performs a log upload.
Note, if you wish enable logs to be uploaded from the device when sap.Logger.upload() is called but do not wish the log to be uploaded each time a settings exchange occurs, comment out the sap.Logger.upload() call in C:\Kapsel_Projects\LoggerDemo\plugins\com.sap.mp.cordova.plugins.settings\www\settings.js and then call cordova prepare. Similarily if you do not wish the log level of the app to be set in the management cockpit, comment out the sap.Logger.setLogLevel call in settings.js.
Note, the automatic log upload performed by the settings plugin fails in SP06 on Android due to issue 1472020964 which is fixed in SP06 PL01.
and add the line
getLogLevel(); //updates the Log Level select to the value returned to the Kapsel app from the SMP 3.0 server
to the end of the success callback of sap.Settings.start (around line 78). This will update the Log Level select to the current log level received during the settings exchange.
- Use the Android IDE or Xcode to deploy and run the project.
Notice that the debug level is ERROR by default. Use the Management Cockpit to change the log level to WARNING and enable the automatic uploading of the log for a particular registration by clicking on the Client Log icon for a registration.
Note, the mapping between the SMP server log levels and the Kapsel log levels is mapped in the method setLogLevel in the following file.
- Hit the back button on Android to close the application. On iOS press the home button to send the app to the background. Press the home button twice quickly and press and hold on the Logger Demo icon until a minus sign appears. Click on it to close Logger Demo.
- Open Logger Demo and notice that the Log Level is now set to WARN. A new log file should also appear under Logs and Traces.
Note, if the log does not appear it may be due to issue 741025.
- In the Management Cockpit it is also possible to click on the log file and have it be downloaded to your computer. This would be useful if the SMP 3.0 server is running on a different machine than the Management Cockpit.