geo6 / zend-expressive-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: 2023-07-22 13:59:16 UTC
README
此库使 Monolog 能够在 Mezzio 中作为 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
。