consolidation/log
Composer 安装命令:
composer require consolidation/log
包简介
Improved Psr-3 / Psr\Log logger based on Symfony Console components.
README 文档
README
Improved PSR-3 Psr\Log logger based on Symfony Console components.
Component Status
In use in Robo.
Motivation
Consolidation\Log provides a PSR-3 compatible logger that provides styled log output to the standard error (stderr) stream. By default, styling is provided by the SymfonyStyle class from the Symfony Console component; however, alternative stylers may be provided if desired.
Usage
$logger = new \Consolidation\Log\Logger($output);
$logger->setLogOutputStyler(new LogOutputStyler()); // optional
$logger->warning('The file {name} does not exist.', ['name' => $filename]);
String interpolation -- that is, the substitution of replacements, such as {name} in the example above, is not required by PSR-3, and is not implemented by default in the Psr\Log project. However, it is recommended by PRS-3, and is often done, e.g. in the Symfony Console logger.
Consolidation\Log supports string interpolation.
A logger manager can be used to delegate all log messages to one or more loggers.
$logger = new \Consolidation\Log\LoggerManager();
$logger->add('default', new \Consolidation\Log\Logger($output));
This is useful if, for example, you need to inject a logger into application objects early (e.g. into a dependency injection container), but the output object to log to will not be available until later.
Comparison to Existing Solutions
Many Symfony Console compoenents use SymfonyStyle to format their output messages. This helper class has methods named things like success and warning, making it seem like a natural choice for reporting status.
However, in practice it is much more convenient to use an actual Psr-3 logger for logging. Doing this allows a Symfony Console component to call an external library that may not need to depend on Symfony Style. Having the Psr\Log\LoggerInterface serve as the only shared IO-related interface in common between the console tool and the libraries it depends on promots loose coupling, allowing said libraries to be re-used in other contexts which may wish to log in different ways.
Symfony Console provides the ConsoleLogger to fill this need; however, ConsoleLogger does not provide any facility for styling output, leaving SymfonyStyle as the preferred logging mechanism for style-conscienscious console coders.
Consolidation\Log provides the benefits of both classes, allowing for code that both behaved technically correctly (redirecting to stderr) without sacrificing on style.
Monolog also provides a full-featured Console logger that might be applicable for some use cases.
consolidation/log 适用场景与选型建议
consolidation/log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65.9M 次下载、GitHub Stars 达 154, 最近一次更新时间为 2016 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 consolidation/log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 consolidation/log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 65.9M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 155
- 点击次数: 22
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-05