PHP code example of tomphp / context-logger

1. Go to this page and download the library: Download tomphp/context-logger 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/ */

    

tomphp / context-logger example snippets




use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use TomPHP\ContextLogger;

$monolog = new Logger('name');
$monolog->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

$log = new ContextLogger($monolog);

$log->addContext('correlation_id', uniqid());

$log->error('There was an error');

$log = new ContextLogger($monolog, ['correlation_id' => uniqid()]);