PHP code example of johnnynotsolucky / monolog-regex-handler

1. Go to this page and download the library: Download johnnynotsolucky/monolog-regex-handler 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/ */

    

johnnynotsolucky / monolog-regex-handler example snippets


use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use johnnynotsolucky\RegexHandler\Handler as RegexHandler;

$handler = new RegexHandler([
    '/^spam log$/', // Match on the message
    ['level_name', '/^(INFO|DEBUG)$/'], // Match on the level_name
    [['context', 'email'], '/@domain\.com$/'] // Match on context->email
]);

$log = new Logger('test');

$log->pushHandler(new StreamHandler('php://stdout'));
$log->pushHandler($handler);

$log->warning('spam log');  // Discarded
$log->info('message'); // INFO and DEBUG logs are discarded
$log->warning('message', ['email' => '[email protected]']); // Discarded on email