PHP code example of leocavalcante / redact-sensitive
1. Go to this page and download the library: Download leocavalcante/redact-sensitive 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/ */
leocavalcante / redact-sensitive example snippets
$sensitive_keys = [
'api_key' => 4,
];
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['api_key' => 4];
$processor = new RedactSensitiveProcessor($sensitive_keys);
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['api_key' => 4];
$processor = new RedactSensitiveProcessor($sensitive_keys);
$logger = new \Monolog\Logger('Readme');
$logger->pushProcessor($processor);
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['api_key' => 4];
$processor = new RedactSensitiveProcessor($sensitive_keys);
$logger = new \Monolog\Logger('Readme', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);
$logger->info('Hello, World!', ['api_key' => 'mysupersecretapikey']);
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['you_know_nothing' => 0];
$processor = new RedactSensitiveProcessor($sensitive_keys);
$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);
$logger->info('Completely hidden', ['you_know_nothing' => 'John Snow']);
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['secret' => 2];
$processor = new RedactSensitiveProcessor($sensitive_keys, template: '%s(redacted)');
$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);
$logger->info('Sensitive', ['secret' => 'my_secret_value']);
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['secret' => 2];
$processor = new RedactSensitiveProcessor($sensitive_keys, template: '...');
$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);
$logger->info('Sensitive', ['secret' => 'my_secret_value']);
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['access_token' => 0];
$processor = new RedactSensitiveProcessor($sensitive_keys, lengthLimit: 5);
$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);
$logger->info('Truncated secret', ['access_token' => 'Very long JWT ...']);
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;
$sensitive_keys = ['credit_card' => -4];
$processor = new RedactSensitiveProcessor($sensitive_keys);
$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);
$logger->info('You are not storing credit cards, right?', ['credit_card' => '4111111145551142']);