PHP code example of bnomei / kirby3-monolog

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

    

bnomei / kirby3-monolog example snippets


monolog()->info('test-' . md5((string) time()), [
    'title' => $page->title(), // field will be normalized
    'page' => $page->id(),
]);

$page->monolog()->info('test-' . md5((string) time()), []);

// write to channel 'default' which writes to file 
// defined at 'bnomei.monolog.file' callback 
$log = \Bnomei\Log::singleton()->channel('default');
// is same as
$log = monolog('default');
// or simply
$log = monolog();

// get a logger instance by channel by name
$securityLogger = monolog('security');

$log = monolog();
$log->warning('Foo');

// or with method chaining
monolog()->error('Bar');

monolog()->info('Adding a new user', [
    'username' => $user->name(),
]);

// increment Field `visits` in current Page
$page = $page->increment('visits');
monolog()->info('Incrementing Field', [
    'page' => $page->id(),
    'visits' => $page->visits()->toInt(),
]);

return [
    // other config settings ...
    // (optional) add custom channels
    'bnomei.monolog.channels' => [
        'security' => function() {
            $logger = new \Monolog\Logger('security');
            // add handlers, formatters, processors and then...
            return $logger; 
        }
    ],
];

return [
    // other config settings ...
    // (optional) add custom channels from other plugins
    'bnomei.monolog.channels.extends' => [
        'myplugin.name.channels', // array of channel definitions in your other option
    ],
];