f-oris / easy-logger
an easy monolog manager
Installs: 2 067
Dependents: 1
Suggesters: 1
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.5
- ext-json: *
- monolog/monolog: ^1.0|^2.0
Requires (Dev)
- mockery/mockery: ^0.9|^1.0
- phpunit/phpunit: ^4.0
This package is auto-updated.
Last update: 2024-11-14 19:55:45 UTC
README
基于monolog/monolog简单封装的日志扩展包。
功能
- 支持多种策略进行日志记录
- 支持自定义扩展日志记录通道
- 可自定义日志配置行为,无配置的情况下,日志写入到系统临时目录下
安装
通过composer引入扩展包
composer require f-oris/easy-logger:^1.1
配置
参考config.example.php
文件
基本用法
1. 写入日志
<?php use Foris\Easy\Logger\Logger; $config = [ // ... ]; $logger = new Logger($config); /** * 写入日志信息 * * 可以使用不同的方法写入不同级别的日志信息 * 下面两种写法等价 */ $logger->debug('调试日志', ['context' => 'context']); $logger->log('debug', '调试日志', ['context' => 'context']); /** * 日志信息信息写入指定通道 */ $logger->channel('channel')->debug('日志信息写入channel通道', ['context' => 'context']);
2. 扩展自定义Logger driver
<?php // 扩展的driver需要实现Psr\Log\LoggerInterface接口规范 $callback = function ($channel) { $logger = new \Monolog\Logger($channel); return $logger->pushHandler(new \Monolog\Handler\TestHandler()); }; $factory = new \Foris\Easy\Logger\Driver\Factory(); $factory->extend($callback, 'test_driver'); $config = [ // ... "channels" => [ // ... "test" => [ "driver" => "test_driver", ] ] ]; $logger = new \Foris\Easy\Logger\Logger($factory, $config); $logger->channel('test')->debug('This is a debug message');
License
MIT License
Copyright (c) 2019-present F.oris us@f-oris.me