SAP Fiori Client Guide

Logger Plugin

(Includes client-side APIs that are supported on Android, iOS, Windows 10). Allows you to log information to trace bugs or other issues in your Hybrid SDK (Kapsel) application for analysis.

With the Logger plugin, you can enable an application to write log entries that can then be automatically uploaded to SAP Mobile Platform Server for analysis by using the sap.Logger.upload() method. If you add the Settings plugin to your project files, sap.Logger.upload() is called with a logon success event (for example, when the application is launched or resumed and logon is successful) so the log file is uploaded automatically. If you do not use the Settings plugin, you can upload log files only by calling the sap.Logger.upload() method manually.

Security for the log upload connection to SAP Mobile Platform Server is provided by using the security profile associated with the Application ID.

You can build in support for logging so that an administrator can remotely set the appropriate log level from SAP Mobile Platform Server. The Kapsel Logger plugin can define each log message with specific levels, such as Debug and Error, which enables you to filter the log message by priority level. The Kapsel Logger plugin mirrors the OData logger library so that it can collect all of the logging data produced by the OData library. The Kapsel plugins use OData libraries in several places so that it can help see and trace the plugins' logging data.

Using the provided sap.Logger.upload() method allows you to log events that occur on the device and send them to SAP Mobile Platform Server, where an Administrator can view them and remotely set the appropriate log level to control the amount of information that is written to the log.


This shows the index.html file for a sample app, which has the appID of "com.mycompany.logger" with the server connection information. This information allows the app to register with the appID on SAP Mobile Platform Server. This sample app logs messages with the log level and uploads a log file to SAP Mobile Platform Server. For example, to log messages with DEBUG log level, you can call the sap.Logger.debug(...) method. You can also use other methods for logging with other log levels (INFO, WARN and ERROR).

        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>  
            logonView = null; 
            logon = null;             
            applicationContext = null;              
            function init() { 
                 var appID = "com.mycompany.logger";  // Change this to app id on server 
               // Optional initial connection context var context = { 
                   "serverHost": "", //Place your SAP Mobile Platform server 3.0 name here                     
                   "https": "false", 
                   "serverPort": "8080",                     
                   "user": "user", //Place your user name for the OData Endpoint here 
                   "password": "xxxxxxx",  //Place your password for the OData Endpoint here                     
                   "communicatorId": "REST",                     
                   "passcode": "password", 
                   "unlockPasscode": "password"                 
               sap.Logon.init(function() { }, function() {alert("Logon Failed"); }, appID, context, sap.logon.IabUi); 
          function logMessage() { 
               var employee = {name: "Dan", location : "Waterloo"}; 
               console.log("The value of employee is " + JSON.stringify(employee));             
          function logMessage2() { 
               sap.Logger.debug("Debug log message"); 
     "Info log message"); 
               sap.Logger.warn("Warn log message"); 
               sap.Logger.error("Error log message");             
          function uploadLog() { 
               sap.Logger.upload(function() {                     
                alert("Upload Successful");                 
               }, function(e) {                     
                alert("Upload Failed. Status: " + e.statusCode + ", Message: " + e.statusMessage);                 
          document.addEventListener("deviceready", init, false);  
          <h1>Logger Sample</h1>  
          <button id="log" onclick="logMessage()">Log Message with console</button><br>  
          <button id="log" onclick="logMessage2()">Log Message with Logging Plugin</button><br>  
          <button id="upload" onclick="uploadLog()">Upload Log</button>  

Setting the Log Level

You can manually set the Kapsel log level in the init(…) function by adding code, for example:

    function(logLevel) {console.log("Log level set");}, 
    function() {console.log("Failed to set log level");});
Log levels are:
  • WARN
  • INFO

By default, only error level logs are captured. Use the setLogLevel to capture other levels. If the log level is DEBUG, all log level messages are stored. If it is WARN, the uploaded log contains WARN and ERROR messages.

On iOS, if the log level is ERROR, then only ERROR level messages are displayed in the console, even if other log level messages are generated. But if the current log level is DEBUG, INFO, or WARN, all generated log messages, regardless of log level, are displayed in the console.On Android, all generated log messages, regardless of log level, are shown in the Android log cat view (console).

To upload the log to the server, in the logMessageInfoToSMP(…) function, enter:
    function(logLevel) {console.log("Log level set");}, 
    function() {console.log("Failed to set log level");});

Domain Whitelisting

Kapsel plugins support Apache Cordova's domain whitelisting model. Whitelisting allows you to control access to external network resources. Apache Cordova whitelisting allows you to whitelist individual network resources (URLs), for example,

For information about the whitelist rules, see published on non-SAP site.