geo6 / mezzio-monolog
Mezzio Monolog 错误处理器
v2.0.2
2020-11-20 13:42 UTC
Requires
- laminas/laminas-dependency-plugin: ^2.1
- laminas/laminas-servicemanager: ^3.4
- mezzio/mezzio: ^3.2
- monolog/monolog: ^1.24 || ^2.0
Requires (Dev)
- phpstan/phpstan: ^0.12.56
- phpstan/phpstan-strict-rules: ^0.12.5
- sentry/sdk: ^3.0
- squizlabs/php_codesniffer: ^3.4
Suggests
- sentry/sdk: Allow sending log messages to Sentry.io
This package is auto-updated.
Last update: 2024-09-22 16:39:46 UTC
README
此库允许在 Mezzio 中将 Monolog 作为 ErrorHandler。
目前支持 2 个处理器(如果需要,还将添加更多)
StreamHandler
:将记录记录到任何 PHP 流中,用于日志文件。SentryHandler
:将记录记录到 Sentry.io(需要sentry/sdk
包)。
安装
composer require geo6/mezzio-monolog
配置
在您的 config
目录中创建一个 monolog.global.php
文件
<?php declare(strict_types=1); return [ // StreamHandler 'stream' => [ 'path' => 'data/log/myapp.log', ], // SentryHanlder 'sentry' => [ 'dsn' => 'https://xxxxx@sentry.io/12345', ], ];
使用方法
要启用它,只需将 Geo6\Mezzio\Monolog\ConfigProvider::class
添加到您的主配置(通常是 config/config.php
)中
...
$aggregator = new ConfigAggregator([
+ Geo6\Mezzio\Monolog\ConfigProvider::class,
...
], $cacheConfig['config_cache_path']);
...
Monolog ErrorHandler 只在 "生产模式"(当 $config['debug']
为 false
时)下生效。
要切换到 "生产模式",您可以使用 composer run development-disable
。