PHP code example of ard / monolog-lgpd

1. Go to this page and download the library: Download ard/monolog-lgpd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ard / monolog-lgpd example snippets


use ARD\Monolog\FilterSensitive\FilterSensitiveProcessor;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('./log.log', Logger::WARNING));

$processor = new FilterSensitiveProcessor();

$log->pushProcessor($processor);

// add records to the log
$log->warning('The user email is [email protected]'); //The user email is ****@domain.com

use ARD\Monolog\FilterSensitive\FilterSensitiveProcessor;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('./log.log', Logger::WARNING));

$processor = new FilterSensitiveProcessor();

$log->pushProcessor($processor);

// add records to the log
$log->warning('The user email is [email protected]',[
'cpf' => '111.111.111-11',
'cnpj' => '11.111.111/0001-00',
'ip' => '10.0.0.10'
]); 

use ARD\Monolog\FilterSensitive\Filter;
use ARD\Monolog\FilterSensitive\FilterSensitiveProcessor;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('./log.log', Logger::WARNING));

$processor = new FilterSensitiveProcessor();

$processor->addCustomFilter(
    new class implements Filter
    {
        public static function pattern(): string
        {
            return '/(^[0-9]{3})\.([0-9]{3})$/';
        }

        public static function replace(): string
        {
            return '$1.***';
        }
    }
);

$log->pushProcessor($processor);

// add records to the log
$log->warning('The user id 123.456'); 

use ARD\Monolog\FilterSensitive\FilterIP;
use ARD\Monolog\FilterSensitive\FilterSensitiveProcessor;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('./log.log', Logger::WARNING));

$processor = new FilterSensitiveProcessor();

$processor->removeFilter(FilterIP::class);

$log->pushProcessor($processor);

// add records to the log
$log->warning('User [email protected] and IP 127.0.0.1');