Skip to Content

/wp-content/uploads/2015/07/sap_logo_750458.png

Logger

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.
image1.PNG

image2.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.  You may also need to execute the following bit of code as mentioned in console.log not working.

if (window.cordova.logger) {
    window.cordova.logger.__onDeviceReady();
}

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.
image9.PNG

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

tag:^(?!(AndroidRuntime|linker|memtrack|dalvikvm|android.os.Debug|jdwp|SoundPool|AudioService|eglCodecCommon))

image10.PNG

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.
image8.PNG

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.

sap.Logger.emailLog()
sap.Logger.getLogEntries()
sap.Logger.upload()

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

sap.Logger.clearLog()

The Kapsel log level can be set.

sap.Logger.setLogLevel(sap.Logger.DEBUG)

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");
sap.Logger.info("Message to be logged at INFO level");    or console.log or console.info("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
    com.mycompany.logger

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

    http://mycompany.com

    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
    or
    cordova run ios

    image3.PNG

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

    image4.PNG

    image11.PNG

    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.
    image7.PNG

    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.

    image12.PNG

    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.
    C:\Kapsel_Projects\LoggerDemo\platforms\android\assets\sap-supportability.properties
    clientLogManager=com.sap.smp.client.supportability.log.ClientLogManagerImpl
    e2eTraceManager=com.sap.smp.client.supportability.e2e.E2ETraceManagerImpl
    file_size=102400
    file_count=10
    file_age=604800000
    

    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. 
    image13.PNG

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

    image5.PNG

    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.
    image6.PNG

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

Back to Getting Started With Kapsel

To report this post you need to login first.

3 Comments

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

  1. Óscar Yuste Romero

    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.

    Óscar

    (0) 
    1. Daniel Van Leeuwen 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”)

      sap.Logger.error(param1);

      sap.Logger.error(param2);


      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



      (0) 

Leave a Reply