As discussed in my previous blog, HCI – Payload Logging using Groovy Scripts logging of payloads should be used prudently. Typically you would like the logging to be disabled and have options to enable this only on a need basis.
If you are from a PI background, you would be well aware of parameters like TRACE_LEVEL, LOGGING_SYNC and Integrated Configuration Logging Options that enable you to turn on / off logging & staging when required. So how can this be done in HCI using the Groovy scripts we described in the previous blogs?
Externalized Parameters in HCI
Some background first – HCI enables you to define parameters that can be controlled externally in your Integration Flow. Typical examples of these are SOAP/HTTP URLs, FTP Server Host,etc which will typically vary in each environment. There is already content on Externalized Parameters for HCI on SCN and would recommend you read that or the corresponding documentation from SAP – Externalizing Parameters of Integration Flow
To be able to define Logging Dynamically we will be using a custom Externalized Parameters, so you can enable and disable logging without having to make changes to your Integration Flow or the Groovy script.
Integration Flow Changes
We will continue to use the sample Integration Flow described in my previous blog with an additional Content Modifier Step and some changes in the Groovy script as described below.
|Groovy Script Change||
Setting of Externalized Parameters
Once the Content Modifier step is defined, the Externalized Parameters tab should contain the Parameter with the name as defined in our Content Modifier step. In this case: externalParamLogger. Set the default value of the Parameter as 0 (Zero). Save and Deploy your Integration Flow.
Test your flow with External Parameter Value set to 0
Trigger your Integration flow with the External Parameter Value set a 0. The Integration Flow executes and the Groovy Script does not log the payload as the value is set to 0. As seen in the image below no attachment is available.
Test your flow with External Parameter Value set to 1
To update your external parameters, navigate to Window –> Show View –> Other. In your Show View dialog box, navigate to Other –> Configurations
Go to Externalized Parameters tab and update the value of externalParamLogger as 1 and click on Save Parameters
Right Click on your project in Configurations –> Deploy Integration Content. Your Integration Flow is now updated to have the Logging Enabled!
Re-trigger the Interface and you should see the logs with the attachment as the Logger is now set to Value 1.
As seen in this blog, Externalized Parameters provide you with options to provide parameters to your Integration flow dynamically. This along with some smart Groovy Scripting enables you to dynamically control payload logging.