Skip to Content

Getting Started with Kapsel – Part 6 — Logger

          /w p-content/uploads/2013/11/sap_logo_334733.png


If you are using SP 13 or higher please see Logger SP13+

The easiest way to log a message in a Kapsel app that is being run on a device or emulator attached to an Android IDE or Xcode, is to simply use the log method.

console.log("Log this");

  This method works in Kapsel apps and in apps being debugged on the desktop using Chrome.image1.PNG


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.  These restrictions are not present on Android.
The console plugin can be added with the cordova plugin add command.

cordova plugin add

Note that the console plugin appears to log messages twice on Android CB-1973.
A log tag filter can be applied to only show messages logged from chromium by editing the message filter named com.mycompany.logger.

Note, in the Eclipse LogCat view, it is 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 logcat > C:\temp\log.txt

On iOS simulators and devices, the output from console.log can be seen in the All Output view.
On iOS devices, the console log can also be viewed by connecting the device to a Mac and in Xcode choosing Window > Organizer > Device > Console as shown below.  Note that the console log file does not stay on the device for very long.

The Kapsel logger plugin enables messages to be logged at one of four levels (Debug, Info, Warn or Error) using

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

It also provides a method,


that when called can upload the log to the SMP 3.0 server.

The default log level is ERROR.  If the log level is set to WARN, then messages logged at WARN or ERROR would appear in the log.

The log level is set by calling


Note, this is a transient setting on iOS and is in effect as long as the application remains in memory.

In addition to the above methods, the Kapsel Logger as of SP05 captures the output of console.log and includes it in the log that can be uploaded to the SMP 3.0 server.  When the Kapsel Logger plugin is included, there is no need for the console plugin so it can be removed by running the below command.

cordova remove org.apache.cordova.console

The console.log entries appear on Android three times one of which is with the log tag of SMP_LOGGER.  The logged entry SMP_LOGGER only appears if the Logger plugin’s log level is set to be INFO or DEBUG. For additional details see the JavaScript file in a project that includes this plugin at


or the JS Documentation at Kapsel Logger API Reference.

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.
    cordova -d create C:\Kapsel_Projects\LoggerDemo com.mycompany.logger LoggerDemo "{\"plugin_search_path\":\"C:/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd LoggerDemo
    cordova -d platform add android
    cordova -d create ~/Documents/Kapsel_Projects/LoggerDemo com.mycompany.logger LoggerDemo "{\"plugin_search_path\":\"/Users/i826567/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd ~/Documents/Kapsel_Projects/LoggerDemo
    cordova -d platform add ios
  • Add the logger plugin.
    cordova -d plugin add
  • Replace www\index.html with index.html.
  • Copy the files to the platform directory by running
    cordova -d prepare
  • Use the Android IDE or Xcode to deploy and run the project.

    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.
    Note as of SMP Server 3.0 SP04 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 that the log entries are in the List Log Format 2.0.
  • Note, if an entry is logged, then upload is called, then another entry is logged and then upload is called, there will only be one log shown in the management cockpit rather than two logs.
  • 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 show 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

You must be Logged on to comment or reply to a post.
  • Hi Daniel


    I'm using AuthProxy (mutual authentication) to register / unRegister SMP server.

    I added the Logon plugin as well but i don't use it explicitly.


    Problem is, when i try to upload the log with the Logger plugin i get an error.

    After debugging things up i manage to locate the error, it is on line 358 on Logger.js file,

    sap.Logon.core.getState function.

    sap.Logon.core is undefined.


    Is this somehow connected to the fact that i didn't used the Logon Plugin?

  • Security advice:

    please make sure you're only logging non-business related data. In case of lost or stolen devices log data can be retrieved and disclose business data or personal data.

    Same goes for any kind of authentication data (user ID, password, cookies, keys)

    • The Logger plugin has a dependency on the Logon plugin so there may be issues if you try to use the Logger plugin without the Logon plugin.  What errors are you seeing?



      Dan van Leeuwen

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