exbico / monolog-db-handler
DB handler for monolog
2.1.0
2023-06-19 12:11 UTC
Requires
- php: ^8.1
- monolog/monolog: ^3.0
Requires (Dev)
- ext-pdo: *
- doctrine/dbal: ^3.6
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.2
- squizlabs/php_codesniffer: ^3.7
Suggests
- ext-pdo: For using the PdoAdapter
- doctrine/dbal: For using the DoctrineDbalAdapter
README
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
- varcharmessage
- varchar|textdatetime
- datetimecontext
- text|json|jsonbextra
- text|json|jsonb