metarush/log-once
Composer 安装命令:
composer require metarush/log-once
包简介
Log messages, usually error messages, only once and optionally get notified. No more flood of error logs with the same message.
README 文档
README
Log messages, usually error messages, only once and optionally get notified. No more flood of error logs with the same message.
Install
Install via composer as metarush/log-once
Sample usage
use MetaRush\LogOnce\LogOnce; $message = 'This is my log'; $hash = \crc32($message); // you can use any hash function of your choice e.g., \md5(), \sha1(), etc (new LogOnce($adapter)) // see adapter examples below ->setTimeZone('UTC') ->setHash($hash) ->setLogMessage($message) ->setNotifiers($notifiers) // optional, see below ->log();
Log adapters
File system
use MetaRush\LogOnce\FileSystem\Adapter as FileSytemLogger; $logDir = '/path/to/logs'; $adapter = new FileSytemLogger($logDir);
Note: To mark a log file as read, rename it with a __ALREADYREAD suffix
e.g., 2021-01-01_00-00-00_+0000__12345__ALREADYREAD.log or you can simply delete the file.
PDO database (e.g., MySQL, PostgreSQL, SQLite)
Create a table with ff. fields:
idINTEGER PRIMARY KEY AUTOINCREMENT,createdOnDATETIME, // must use YYYY-MM-DD HH:MM:SShashTEXT, // make length as long as your hash function's output e.g., if \md5(), must be 32messageTEXT, // make length as long your log messagesalreadyReadINTEGER // will have 1 or 0 value, can be ENUM or UNSIGNED TINY INT if you want
use MetaRush\DataMapper\Builder as DataMapperBuilder; use MetaRush\LogOnce\Pdo\Adapter as PdoLogger; $dataMapper = (new DataMapperBuilder) ->setDsn('mysql:host=localhost;dbname=yourLogDb') ->setDbUser('user') ->setDbPass('pass'); ->build(); $adapter = new PdoLogger($dataMapper, 'yourLogTable');
Note: To mark a log row as read, set the alreadyRead column to 1 or you can simply delete the row.
Notifiers
We use the package metarush/notifier as notifier
use MetaRush\Notifier\Pushover\Builder as PushoverNotifier; // define a Pushover notifier $pushoverNotifier = (new PushoverNotifier) ->addAccount('pushover_app_key', 'pushover_user_key') ->setSubject('test subject') ->setBody('test body') ->build(); // $emailNotifier = (new EmailNotifier)...; // optionally add other notifiers $notifiers = [$pushoverNotifier, $emailNotifier];
Inject $notifiers in ->setNotifiers($notifiers) to the sample usage above.
For more info on how to use other available notifiers such as email visit metarush/notifier
Viewing logs
A UI to view the logs is not included in this package. You can simply use whatever database admin tool you're using if you're using PDO logger, or manually view the file system, if you're using the File system logger.
metarush/log-once 适用场景与选型建议
metarush/log-once 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「logger」 「error log」 「error logger」 「Error logging」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 metarush/log-once 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 metarush/log-once 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 metarush/log-once 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Workflow logger
HTTP request logger middleware for Laravel
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 148
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-13