PHP code example of l0rb / monolog-pdo-handler

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

    

l0rb / monolog-pdo-handler example snippets


//Import class
use Monolog\Logger;
use KarelWintersky\Monolog;

// Create log handler
// using table `log` with additional fields
// `filename`, `filesize`, `filetime`
// and index at field `filename`
// minimum logging level is INFO.

$log_handler = new KWPDOHandler($pdo_handler, 'log', [
    'filename'  =>  'VARCHAR(32)',
    'filesize'  =>  'BIGINT(20) DEFAULT NULL',
    'filetime'  =>  'DATETIME'
], [
    'filename'  =>  'CREATE INDEX filename on `%s` (`filename`) USING HASH',
], Logger::INFO);

// Create logger
$monologger = new \Monolog\Logger($monolog_channel);

// Set handler
$monologger->pushHandler($log_handler);

// Now you can use the logger, and further attach additional information
$monologger->notice("File information", [
    'filename'  =>  $data['filename'],
    'filesize'  =>  $data['filesize'],
    'filetime'  =>  $data['filetime']
]);