Skip to Content
Author's profile photo Daniel Van Leeuwen

Getting Started with Kapsel – Part 6 — Logger (SP09+)



The easiest way to log a message in a Kapsel app that is being run on a device or emulator is to use the console.log method.

console.log("Log this");

  This method works in Kapsel apps and in regular web apps being debugged on the desktop using Chrome.
Note the two screenshots below show a message being logged following the call to console.log in monitor.bat which is part of the Android SDK and in Xcode.


Note that in an iOS Cordova app, it requires adding the console plugin, the import of cordova.js, and will only work after the deviceready event is fired.  You may also need to execute the following bit of code as mentioned in console.log not working.

if (window.cordova.logger) {

The console plugin can be added with the cordova plugin add command.

cordova plugin add cordova-plugin-console

For Android, a log tag filter can be applied to only show messages logged from chromium.

Note it is also possible to exclude certain tags from the view by entering a regular expression such as



If using an Android device or simulator, the Android log file can be retrieved from the device using adb which is part of the Android SDK.

adb logcat > C:\temp\log.txt

On iOS simulators and devices, the output from console.log can be seen in the All Output view in Xcode.
On devices, the console log can also be viewed by connecting the device to a Mac and in Xcode choosing Window > Device and if needed click on the up-triangle at the bottom left.

The Kapsel logger plugin saves messages logged using console.log into a separate log file that can be emailed from the device, viewed on the device, or uploaded to an SMP server via the following commands.


As of SP10, it also has a method to clear the log.


The Kapsel log level can be set.


The default log level is ERROR.
Note the log level once set is persistent between application restarts.

The logger plugin will only save messages that are logged at a higher level than the apps current log level.  For example if the log level is sap.Logger.WARN and a message is logged at the DEBUG level, it will not be saved to the log.

Messages can be logged  at one of four levels (Debug, Info, Warn or Error) using

sap.Logger.debug("Message to be logged at DEBUG level");  or console.debug("Message to be logged at DEBUG level");"Message to be logged at INFO level");    or console.log or"Message to be logged at INFO level");
sap.Logger.warn("Message to be logged at WARN level");    or console.warn("Message to be logged at WARN level");
sap.Logger.error("Message to be logged at ERROR level");  or console.error("Message to be logged at ERROR level");

For additional details on the Logger plugin, see C:\SAP\MobileSDK3\KapselSDK\docs\api\sap.Logger.html or Using the Logon Plugin.

The following steps will demonstrate this plugin.

  • Follow the steps shown in Configuring a Kapsel App in the Management Cockpitto create an Application with the application id of

      This app does not use an OData endpoint so that can be set to a dummy URL such as

    and add the Basic SSO mechanism.

  • Create the project and add the logger plugin.
    cordova create C:\Kapsel_Projects\LoggerDemo com.mycompany.logger LoggerDemo
    cd LoggerDemo
    cordova platform add android
    cordova plugin add kapsel-plugin-logger --searchpath %KAPSEL_HOME%/plugins
    cordova create ~/Documents/Kapsel_Projects/LoggerDemo com.mycompany.logger LoggerDemo
    cd ~/Documents/Kapsel_Projects/LoggerDemo
    cordova platform add ios
    cordova plugin add kapsel-plugin-logger --searchpath $KAPSEL_HOME/plugins
  • Replace www\index.html with index.html.
  • Prepare, build and deploy the app with the following command.
    cordova run android
    cordova run ios


    Here are the results after setting the log level to INFO, Log using console.log, Log using sap.Logger at WARN level.



    As shown above on Android, a log filter can be used that filters on the Log Tag SMP_LOGGER.

  • Pressing the Upload Log button causes the log file to be uploaded to the server.
    In order for the call to sap.Logger.upload() to succeed, the Log Upload checkbox on the registration ID in the Management Cockpit must be checked.

    Note, the Log Type drop down in the Client Logging dialog can change the log level set for the application when used with the Settings plugin.
    It is possible to set the Log Upload to be enabled for each new registration via the Application > Client Policy > Client Log Policy settings.
    The log once uploaded to the SMP server can be viewed under Logs > Logs & Traces as shown below.


    Note, if an entry is logged, then upload is called, then another entry is logged and then upload is called, there may only be one log upload shown in the management cockpit rather than two log uploads.  In this case both log messages will appear in the first log upload. 

  • Note that the log entries are in the List Log Format 2.0.
  • On Android, by default there are 10 log files with a default size of 100KB.  When all 10 log files are full, the first log file is erased and then written to.  When the log files are uploaded to the SMP server following a call to sap.Logger.upload, the logs on the device are erased.  The number of log files and the file size can be set in a properties file.

    The file_age is in milliseconds.  The default shown above is 7 days.  After seven days, the logs are erased.

    The log files can become full quickly so it is recommend to increase these settings.  The log files can be viewed on an emulator. 

  • In addition to the application specific log file, there are logs that contain information about registration, deregistration, application settings, proxy, push etc. as shown below.
    Note, that the Status drop down is set to PATH(ALL) which lists all logged messages.  If it is set to debug, only debug messages will be shown and not warning or error level messages.


    Note, in order for this information to be captured, the component log level needs to be set and the Trace set to enabled as shown below.

    Finally there is a log file for the SMP server under the tab Log Files.

Back to Getting Started With Kapsel

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Daniel Van Leeuwen
      Daniel Van Leeuwen
      Blog Post Author

      Updated the sample to include

      Author's profile photo Former Member
      Former Member

      Hello Daniel,

      I have a doubt about the scope of this plugin and I would like to know his applications in a development.

      My scenario is:

      • Hybrid application based in Kapsel plugins (including Logon plugin and Odata plugin) and Sencha as JS framework

      Our purpose should be to know the errors or crashes occurred in the application (as message log) individually for each user, for example, displaying info errors.. is that possible? Currently we have a ignorance about "deep" bugs because it is needed to debug in the console (independently of the platform) to know info errors included in my "console.log()"  but you know this is not possible in a "production" environment. Any suggestion for this implementation, maybe I am wrong in the real environment this plugin is used and its purposes.

      Thank you so much.


      Author's profile photo Daniel Van Leeuwen
      Daniel Van Leeuwen
      Blog Post Author

      Certainly you can instrument your code with

      sap.Logger.error("~~~## The following error occurred in the method xyz.  The parameters it was called follow")



      Then you can periodically have the log file be either examined on the device, or the log file be emailed from the device or have it be uploaded to the SMP server.

      I would recommend adding some unique string to the messages so you can more easily filter on the message you are interested in.

      Hope that helps,

      Dan van Leeuwen