The Kapsel Logger plugin provides a Cordova plugin wrapper around the SAP Mobile Platform client logging API.
The Logger plugin has ERROR, WARN, INFO, and DEBUG log levels and log messages are captured based on the configured and selected log level. A Kapsel application can be set to these log levels by programmatic control, and by the administrator changing a setting on the server. For Android and iOS, the default log level is ERROR, so by default only ERROR level logs are captured. sap.Logger.setLogLevel() method is used to set other levels. If you want to get log messages at all log levels, you must set the log level to DEBUG. (DEBUG < INFO < WARN < ERROR)
If the log level is set to DEBUG, the application captures all log messages.
If you set the log level to INFO, the application captures INFO, WARN, and ERROR log messages.
If you set the log level to WARN, the application captures WARN and ERROR log messages.
If you set the log level to ERROR, the application captures only Error log messages.
Using the provided sap.Logger.upload() method allows developers to upload a log file 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. When the sap.Logger.upload() method is triggered, a log file will be uploaded. If the Log Upload checkbox is selected in the Management Cockpit, the client can upload a log file by calling sap.Logger.upload(). If the Log Upload checkbox is disabled in the Management Cockpit, the client does not upload the log file to the server. The attempt to upload causes an "HTTP/1.1 403 Forbidden" error. To support manual uploading of the log, you should implement a button or some other mechanism that calls sap.Logger.upload() when needed.
For the Logger plugin to upload a log file these conditions must be met: 1) Log Upload checkbox enabled In the Management Cockpit 2) sap.Logger.upload() is called by developer.
The expected work flow, with the current architecture consists of the following:
1) If a user has an issue that needs to be analyzed by an administrator or developer, the user reports the issue as appropriate.
2) The administrator, or developer, enables the log collection for the user on the SAP Mobile Platform server.
3) The administrator lets the user know that he, or she, can upload log file.
4) The user uploads thelog file to the server, and the administrator gets the uploaded log file in the Management Cockpit.
5) The administrator sends the file to the developer to debug.
Currently, on iOS, if the current log level is ERROR (default level), only ERROR level messages are displayed on 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 on the console.
On Android, if the current log level is ERROR, only ERROR level messages are displayed in the Android logcat view (console). if log level is INFO, then ERROR, WARN and INFO level messages are displayed in the Android logcat view (console).
When the Kapsel Settings plugin is added to the project, Settings will: 1) Get log level from the server 2) Set it into Logger on the client 3) Call sap.Logger.upload() after a logon success event, for example, when the app is launched or resumed and logon is successful. The Settings plugin retrieves the selected log level(type) from the Management Cockpit on the server, sets the log level to Logger plugin, and then automatically uploads a log file to the server. If the Settings plugin is not added to the project, a log file can be uploaded only by the developer calling the sap.Logger.upload() method manually. To upload a log file automatically, settings plugin is required. In the Management Cockpit, in the Client Logging dialog box, the Log Upload checkbox is able to enable or disable log file upload, and you can choose the log type(level). You can also view a list of the uploaded log files. On the server side, there are seven log types: NONE, FATAL, ERROR, WARNING, INFO, DEBUG and PATH. Since the Kapsel Logger plugin supports only DEBUG, INFO, WARN, and ERROR, the Logger plugin implicitly matches FATAL to ERROR, and PATH to DEBUG. If NONE is set in the Management Cockpit, Logger sets it to default log level.
Adding and Removing the Logger Plugin
Add or remove the Logger plugin using the Cordova CLI.
To add the Logger plugin to your project, use the following command:
Cordova plugin add <path to directory containing Kapsel plugins>\logger
To remove the Logger plugin from your project, use the following command:
cordova plugin rm com.sap.mp.cordova.plugins.logger
|debug( message, [tag], [successCallback], [errorCallback] )||Add a debug message to the log.|
|emailLog( [to], [subject], [message], [successCallback], [errorCallback] )||Email the contents of the log as an attachment.|
|error( message, [tag], [successCallback], [errorCallback] )||Add an error message to the log.|
|getLogEntries( successCallback, errorCallback )||Get log entries.|
|getLogLevel( successCallback, [errorCallback] )||Get log level.|
|info( message, [tag], [successCallback], [errorCallback] )||Add an info message to the log.|
|setLogLevel( level, [successCallback], [errorCallback] )||Set log level.|
|upload( successCallback, errorCallback )||Upload a log file, with log entries, to SAP Mobile Platform server.|
|warn( message, [tag], [successCallback], [errorCallback] )||Add a warning message to the log.|