radphp/logging
Composer 安装命令:
composer require radphp/logging
包简介
RadPHP logging component
关键字:
README 文档
README
The Logging library provides multiple logging adapters using a simple interface. With the Logger class it is
possible to send a single message to multiple logging adapters at the same time.
By default you can use File or Null as logging adapters, but you can use any
object implementing Rad\Logging\AdapterInterface as an adapter for the Logger class.
Usage
You can create new instance adapter and attached to the Logger class. An example would be:
use Rad\Logging\Logger; use Rad\Logging\Adapter\FileAdapter; // Attach single or multiple adapters $logger = new Logger(); $logger->attachAdapter(new NullAdapter()); $logger->attachAdapter(new FileAdapter('/path/to/file.log')); // Or attaching your adapter $logger->attachAdapter(new MyAdapter()); // You can pass message to these log levels $logger->emergency('Something did not work'); $logger->alert('Something did not work'); $logger->critical('Something did not work'); $logger->error('Something did not work'); $logger->warning('Something did not work'); $logger->notice('Something did not work'); $logger->info('Something did not work'); $logger->debug('Something did not work');
The log output is below:
09/Apr/2016 11:18:55 UTC [EMERGENCY] Something did not work
09/Apr/2016 11:18:55 UTC [ALERT] Something did not work
09/Apr/2016 11:18:55 UTC [CRITICAL] Something did not work
09/Apr/2016 11:18:55 UTC [ERROR] Something did not work
09/Apr/2016 11:18:55 UTC [WARNING] Something did not work
09/Apr/2016 11:18:55 UTC [NOTICE] Something did not work
09/Apr/2016 11:18:55 UTC [INFO] Something did not work
09/Apr/2016 11:18:55 UTC [DEBUG] Something did not work
The log message may contain placeholders. Placeholder names must correspond to keys in the context array.
Placeholder names must be delimited with a single opening brace { and a single closing brace }. There must not be any whitespace between the delimiters and the placeholder name.
Placeholder names should be composed only of the characters A-Z, a-z, 0-9, underscore _, and period .. The use of other characters is reserved for future modifications of the placeholders specification.
The following is an example uses placeholder in log message:
use Rad\Logging\Logger; use Rad\Logging\Adapter\FileAdapter; $logger = new Logger(); $logger->attachAdapter(new FileAdapter('/path/to/file.log')); $logger->info('User "{user_id}" successfully logged in.', ['user_id' => 2]);
Transactions
Transactions store log data temporarily in memory and later on write the data to all adapters.
use Rad\Logging\Logger; use Rad\Logging\Adapter\FileAdapter; $logger = new Logger(); $logger->attachAdapter(new FileAdapter('/path/to/file.log')); $logger->begin(); try { //Code here $logger->commit(); } catch (\Exception $e) { $logger->rollback(); throw $e; }
Formatter
You can use formatter for format log lines or implementing your own formatter. Your formatter must be implemented Rad\Logging\FormatterInterface, Default formatter is LineFormatter
use Rad\Logging\Logger; use Rad\Logging\Adapter\FileAdapter; $logger = new Logger(); $fileAdapter = new FileAdapter('/path/to/file.log'); $fileAdapter->setFormatter(new LineFormatter("%time% :: {%level%} :: %message%\n", 'G:i:s T')); $logger->attachAdapter($fileAdapter); $logger->emergency('Something did not work'); $logger->alert('Something did not work');
The log output with new format:
11:18:55 UTC :: {EMERGENCY} :: Something did not work
11:18:55 UTC :: {ALERT} :: Something did not work
These variables available for LineFormatter:
| Variables | Description |
|---|---|
| %time% | Log time |
| %level% | Log level |
| %message% | Log message |
radphp/logging 适用场景与选型建议
radphp/logging 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「component」 「RadPHP」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 radphp/logging 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 radphp/logging 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 radphp/logging 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FSi DataSource Component
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Priveate for SkeekS CMS
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-13