martes, 13 de agosto de 2019

UI5 framework Logging and Tracing

Write debug logs in the console for debugging application logic.


1) enable the app to show information necessary for debugging in the index.html file.


webapp/index.html

<!DOCTYPE HTML>
<html>

       <head>
                     <meta charset="utf-8">
           <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>movies</title>
              <script id="sap-ui-bootstrap"
                     src="../../resources/sap-ui-core.js"
                     data-sap-ui-theme="sap_belize"
                     data-sap-ui-resourceroots='{"xxx.xxx": "./"}'
                     data-sap-ui-compatVersion="edge"
                     data-sap-ui-logLevel="debug"
                     data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
                     data-sap-ui-async="true"
                     data-sap-ui-frameOptions="trusted">
              </script>
       </head>

Logging messages in the console might slow down the execution time. Remove the flag when the debugging is finished.

2) Set the Log function in the App.controler.js


webapp/controller/App.controller.js


sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/base/Log"
], function (Controller, Log) {
       "use strict";

       return Controller.extend("xx.xx.controller.App", {
             
              onInit: function () {
                     Log.info("Controller has been initialized.");
              },
             
              onExit: function () {
                     Log.info("Controller will shortly be destroyed.");
              },

              onPress: function (sValue) {
                     sap.ui.require(["sap/m/MessageToast"], function (oMessage) {
                           oMessage.show("Searching..." + sValue);
                     });
              }
             
       });
});



3) open the browser console to see the logged message.




Logging and Tracing reference: https://ui5.sap.com/#/topic/9f4d62c6648a423d85aaf2bfc2c7ddfe