juanchosl/logger
Composer 安装命令:
composer require juanchosl/logger
包简介
Little logger using the PSR interfaces
README 文档
README
Description
Little adapter to save log data using PSR3. This library have the availability of put the data log into distincts repositories or with different format. We can change the destination of the data, or his format, only changing the injected dependency.
We can create distincts log for differents cases, save it with an alias into the Debugger instance and call or inject any one into a any lib. In example, we can create a log for database queries, other for debug, other for errors...
Installation
Use composer in order to install it
composer require juanchosl/logger composer update
How to use
First steps
Create or use provided Data Composers,
Using composers, you can create and design your own messages structure, you can convert to String (for save into files) or can convert to Array or Objects in order to save into tables.
Actually we have availables 3 types of Composers:
- TextComposer
- ArrayComposer
- ObjectComposer
$composer = new TextComposer;
Create or use a provided repository
Is the message destination, you can use the same Composer for save data to few Repositories, mantaining the same structure for all, create an instance in order to put the composer
Actually we have availables 3 Repositories
- FileRepository (needs to provide a filepath)
- ScreenRepository (do ECHO, converting iterable entities with print_r, json_encode, casting to string or performing a var_dump)
- StreamRepository, as Screen, convert variables, capturing it and send to a stream, as a body from a PSR Response
$repository = new FileRepository(PATH . DIRECTORY_SEPARATOR . 'error.log'); $repository->setComposer($composer);
Logger
Declare a Logger directly
$logger = new JuanchoSL\Logger\Logger($repository); $logger->error("This is a message error");
Declare a Logger using the provided Debugger class
use JuanchoSL\Logger\Debugger; $debugger = Debugger::init(); $debugger->setLogger('errors', $logger); //.... your code ... Debugger::get('errors')->error("This is a message error");
Declaring few Loggers in order to save separated data
use JuanchoSL\Logger\Debugger; $debugger = Debugger::init() ->setLogger('errors', $logger) ->setLogger('database', new Logger((new ModelRepository())->setComposer(new ObjectComposer))); //.... your code ... Debugger::get('errors')?->error("This is a message error"); Debugger::get('database')?->debug($sql);
Error control
Initializing error or exception handlers
use JuanchoSL\Logger\Debugger; $debugger = Debugger::init()->setLogger('errors', $logger)->initFailuresHandler('errors', E_ALL^E_USER_NOTICE);
Use declared Loggers for inject as dependecy into Libraries
use JuanchoSL\Logger\Debugger; use JuanchoSL\Orm\Engine\Drivers\Mysqli; $debugger = Debugger::init() ->setLogger('errors', $logger) ->setLogger('database', new Logger((new ModelRepository())->setComposer(new ObjectComposer))) ->initFailuresHandler('errors', E_ALL^E_USER_NOTICE); $database = new Mysqli($credentials); $database->setLogger($debugger->getLogger('database'));
juanchosl/logger 适用场景与选型建议
juanchosl/logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 378 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「debug」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 juanchosl/logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juanchosl/logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 juanchosl/logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
Analysis module for finding problematical shop data.
Twig extensions for Tracy Debugger
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 378
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 9
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-27