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) {
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.
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))
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.
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.
com.mycompany.logger
This app does not use an OData endpoint so that can be set to a dummy URL such ashttp://mycompany.com
and add the Basic SSO mechanism.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
cordova run android
or
cordova run ios
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.You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
25 | |
21 | |
12 | |
9 | |
8 | |
8 | |
8 | |
8 | |
8 |