enlitepro / enlite-monolog
Laminas 与 Monolog 集成
3.0.0
2021-07-13 01:16 UTC
Requires
- php: ^7.1 || ^8.0
- container-interop/container-interop: ^1.0
- laminas/laminas-servicemanager: ^3
- laminas/laminas-stdlib: ^3
- monolog/monolog: ^1.3 || ^2.0
Requires (Dev)
- johnkary/phpunit-speedtrap: ^3.0
- php-parallel-lint/php-parallel-lint: ^1.3
- phpunit/phpunit: ^7.5.20 || ^8.5.2 || ^9.5.6
- squizlabs/php_codesniffer: ^3.0
README
通过具有出色日志系统的 monolog 与 Laminas 集成
安装
推荐通过命令行使用 composer 安装。
composer require enlitepro/enlite-monolog
用法
- 将
EnliteMonolog
添加到您的config/application.config.php
中以启用模块。
// usage over service locator $serviceLocator->get('EnliteMonologService')->debug('hello world'); use EnliteMonolog\Service\MonologServiceAwareInterface, EnliteMonolog\Service\MonologServiceAwareTrait; // usage in your services class MyService implements MonologServiceAwareInterface { use MonologServiceAwareTrait; public function whatever() { $this->getMonologService()->debug('hello world'); } }
- 将模块中的配置文件
config/monolog.global.php.dist
复制到您的项目的 config/autoload。
默认情况下,它将日志写入 data/logs/application.log
。如果想要更改此行为,请按照以下配置添加您的设置
'EnliteMonolog' => array( 'EnliteMonologService' => array( // Logger name // 'name' => 'EnliteMonolog', // Handlers, it can be service locator alias(string) or config(array) 'handlers' => array( // by config 'default' => array( 'name' => 'Monolog\Handler\StreamHandler', 'args' => array( 'stream' => 'data/log/application.log', 'level' => \Monolog\Logger::DEBUG, 'bubble' => true ), 'formatter' => array( 'name' => 'Monolog\Formatter\LogstashFormatter', 'args' => array( 'applicationName' => 'My Application', ), ), ), // by service locator 'MyMonologHandler' ) ), // you can specify another logger // for example ChromePHPHandler 'MyChromeLogger' => array( 'name' => 'MyName', 'handlers' => array( array( 'name' => 'Monolog\Handler\ChromePHPHandler', ) ) ) ),
现在您可以开始使用了
$serviceLocator->get('EnliteMonologService')->debug('hello world'); $serviceLocator->get('MyChromeLogger')->debug('hello world');
贡献
此库旨在遵守 PSR-1、PSR-2 和 PSR-4。如果您发现遵守上的疏忽,请通过 pull request 发送补丁。