metarush/log-once 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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:

  • id INTEGER PRIMARY KEY AUTOINCREMENT,
  • createdOn DATETIME, // must use YYYY-MM-DD HH:MM:SS
  • hash TEXT, // make length as long as your hash function's output e.g., if \md5(), must be 32
  • message TEXT, // make length as long your log messages
  • alreadyRead INTEGER // 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 metarush/log-once 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 148
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-13