exbico / monolog-db-handler
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
安装
安装此扩展的首选方式是通过 composer
composer require exbico/monolog-db-handler
基本用法
<?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));
您需要创建以下字段的所需表格集
level
- varcharmessage
- varchar|textdatetime
- datetimecontext
- text|json|jsonbextra
- text|json|jsonb