Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_vL
Product and Topic Expert
Product and Topic Expert

         

Logger


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.

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 https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git

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

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

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");
sap.Logger.info("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,

sap.Logger.upload()

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

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

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

project_name\www\plugins\com.sap.mp.cordova.plugins.logger\www\logger.js

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
    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.
    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 com.sap.mp.cordova.plugins.logger
  • 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.
    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. 


  • 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

20 Comments