PHP code example of baohan / monolog

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

    

baohan / monolog example snippets


use Baohan\Monolog\Logger\AppLogger;
use Monolog\Logger;

Logger('demo', $extra);
// or grab http request data as extra
// $extra = AppLogger::getExtraFromRequest($request);
// AppLogger::setExtra($log, $extra);
$log->pushHandler(AppLogger::getConsoleHandler(Logger::DEBUG));
$log->pushHandler(AppLogger::getStreamHandler('debug.log', Logger::DEBUG));
$log->pushHandler(AppLogger::getStreamHandler('error.log', Logger::ERROR));
$log->pushHandler(AppLogger::getBearychatHandler('YOUR_API_KEY', Logger::CRITICAL));

$context = [
    'page' => 'demo.php'
];
$log->debug('The first debug message', $context);

$ php demo.php
> [2020-01-02T07:30:02.602905+00:00] demo.DEBUG: The first debug message {"page":"demo.php"} {"key1":"val1"}