Klarna Docs - Extend the logging filter

Extend the logging filter


In this post you will learn where to hook into the module to extend the logging filtering in the Klarna production environment for the Klarna Checkout.

Information are logged to have a better analyses of what is happening and to improve the trouble shooting. These information can be just debug output to know in which step of a workflow is happening a specific action. But these information can also contain customer related information. The Klarna Checkout module already is filtering a specific set of information to ensure data privacy in all markets. But there can be always cases where this set is not enough even when they follow the market privacy rules. For these scenarios the set can be extended.

Extending the filtering can be useful so that still less information of a customer are visible to other people. Either these information are not needed or there is a more strict careness about the data of the customer.

1. Checkout how Klarna's filtering logic is working
The filtering of information is happening in the class \Klarna\Base\Logger\Cleanser. The set is defined in the attribute "$privateKeys":

 public $privateKeys = [

When Klarna logs something then these the value of these keys won't be written to the log file.

2. Create a own cleanser class and extend the Klarnas filtering set
Please create a class as follows:

namespace A\B\C;

      class MyCleanser extends \Klarna\Base\Logger\Cleanser
        public function __construct(array $filterKeys = [])
          $this->privateKeys = arraymerge($this->privateKeys, $filterKeys);

You can see that this class extends the class from the Klarna Checkout module. Moreover the constructor has an own argument of filter. In the end the filter set of Klarna will be merged with the $filterKeys list.

3. Adding your cleanser class in the Klarna logging workflow
Now please add the following entries to your etc/di.xml file:

<type name="A\B\C\myCleanser">
     <argument name="filterKeys" xsi:type="array">
        <item name="new_filter_key" xsi:type="string">new_filter_key</item>
<type name="Klarna\Base\Logger\Logger">
     <argument name="cleanser" xsi:type="object">A\B\C\MyCleanser</argument>

Your new class will now be used except Klarna ones. Moreover when there is a key with the name "new_filter_key" it will be filtered. Of course you can indicate other keys - this one is just there for demonstration purpose.

4. Run the Magento cli commands so that Magento knows about this new entry

After these steps you will now not just filter keys which are defined from the Klarna Checkout module but also defined from you.