exbico/monolog-db-handler

DB handler for monolog

2.1.0 2023-06-19 12:11 UTC

This package is auto-updated.

Last update: 2024-04-20 07:43:37 UTC


README

ci Latest Stable Version Total Downloads License

INSTALLATION

The preferred way to install this extension is through composer:

composer require exbico/monolog-db-handler

Basic Usage

<?php

use Monolog\Level;
use Monolog\Logger;
use Exbico\Handler\DbHandler;
use Exbico\Handler\DbHandlerConfig;
use Exbico\Handler\Connection\PdoAdapter;

$connection = new PdoAdapter(new PDO(dsn: 'pgsql:dbname=foo;host=127.0.0.1', username: 'root', password: null));

$logger = new Logger('example',[new DbHandler(connection: $connection)]);

// You can also specify which level of messages should be logged and the table name for each level

$config = new DbHandlerConfig(
    emergency: 'log_emergency',
    alert:     'log_alert',
    critical:  'log_critical',
    error:     'log_error',
    warning:   'log_warning',
    notice:    'log_notice',
    info:      'log_info',
    debug:     null, // debug level will not be logged
);

$logger->pushHandler(new DbHandler(connection: $connection, config: $config));

You need to create set of required tables with the following fields:

  • level - varchar
  • message - varchar|text
  • datetime - datetime
  • context - text|json|jsonb
  • extra - text|json|jsonb