承接 mvf-tech/system_logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mvf-tech/system_logger

Composer 安装命令:

composer require mvf-tech/system_logger

包简介

A package used to perform DataDog and system logs

README 文档

README

A package used to perform DataDog and system logs

Releases

Installation and Setup

  1. Run composer require mvf-tech/system_logger to install the package
  2. You will also have to set DATADOG_PROJECT_NAME and DATADOG_SERVICE_NAME ENV variables

Basic Use

use MVF\SystemLogger\Reporters\Remotes\DataDog\DataDog;
use MVF\SystemLogger\Reporters\Host\CommandLine;
use MVF\SystemLogger\SystemLogger;

$logger = new SystemLogger();
$logger->info(
    ["some_kind_of_tag", "key" => "another_tag"],
    "message",
    new CommandLine(),
    DataDog::histogram("metric_name_suffix", 2)
);

There are two type of reporters available, host reporters, CommandLine in the above example, and remote reporters, DataDog.histogram(...) in the above example. host reporters are used to log messages, these reporters do not receive the list of tags and therefore are not able to do anything with it. remote reporters are used to make more complex logs, they receive only the list of tags, the message is appended to the tag list as "message" => "the message". You can create your own reporters by implementing HostLogInterface or RemoteLogInterface more about this later.

SystemLogger

include:

  • use MVF\SystemLogger\SystemLogger;

methods:

  • ->info(array $tags, string $message, (HostLogInterface|RemoteLogInterface) ...$loggers)

  • ->warning(array $tags, string $message, (HostLogInterface|RemoteLogInterface) ...$loggers)

  • ->error(array $tags, string $message, (HostLogInterface|RemoteLogInterface) ...$loggers)

The system logger is used as a central storage unit, it does not perform any logging by itself instead it is responsible for message processing and reduction of code duplication since the same tags and message are passed to all of the provided reporters.

Default Tags

The following are the default tags that will be appended to the provided list.

  • info, warning or error one of these will be appended based on which system logger function was called.

Message Placeholders

There are two kinds of message placeholders tag and reporter.

$logger->info(
    [
        "name" => "Bob"                     // tag key name
    ], 
    "There are :1 messages from :name",
    new CommandLine(),                      // reporter index 0
    DataDog::histogram("messages", 2),      // reporter index 1
    ...                                     // reporter index ...
);

tag placeholder is identified with a : followed by the key of one of your tags, in the above example :name is a valid tag. reporter placeholder is identified by : followed by the index of one of your reporters so in the above example :1 would be replaced with the value of DataDog.histogram("messages", 2) which in this case would be 2.

#####Notes

  • :0 would not be replaced since CommandLine implements HostLogInterface and host reporters do not have any return value.

Default Reporters

These are responsible for the actual logging of information. At the moment there are two default reporters built in CommandLine and DataDog.

CommandLine

This is a basic reporter that will simply echo messages to the standard out.

DataDog

include:

  • use MVF\SystemLogger\Reporters\Remotes\DataDog\DataDog;

methods:

  • ::gauge(string $suffix, int $value): Gauge
  • ::histogram(string $suffix, int $value, float $sample_rate = 1.0): Histogram
  • ::time(string $suffix, (float|callable) $time): Time
  • ::unique(string $suffix, int $value): Unique

suffix is the last part of your DataDog metric name. All DataDog metric names will consist of DATADOG_PROJECT_NAME.suffix where DATADOG_PROJECT_NAME is loaded from ENV, if these variables are not set then the beginning of your metric will default to notset.suffix. In Addition all DataDog logs will be sent with additional tag DATADOG_SERVICE_NAME which is also loaded from ENV, if this variable is not set then it will default to value notset.

Custom Reporters

You can create your own host or remote reporters by creating a class and implementing HostLogInterface or RemoteLogInterface respectively.

HostLogInterface

include:

  • use MVF\SystemLogger\HostLogInterface;

methods:

  • ->info(string $message): \Exception|null : should make a log with info severity.

  • ->warning(string $message): \Exception|null : should make a log with warning severity.

  • ->error(string $message): \Exception|null : should make a log with error severity.

Each method receives the message with replaced placeholders. If an exception is thrown in the reporter then it should be caught and returned, the system logger will re-throw it once all other logs are performed. An example of laravel standard out reporter can be found here.

RemoteLogInterface

include:

  • use MVF\SystemLogger\RemoteLogInterface;

methods:

  • ->send(string[] $tags): \Exception|null : tags array will always have at least these values [ "<info|warning|error>", "message" => "<message>", <DATADOG_SERVICE_NAME> ]. If an exception is thrown in the reporter then it should be caught and returned, the system logger will re-throw it once all other logs are performed.

  • ->getValue(): string|int : if your remote reporter has a value that may be returned then this function should return it, otherwise return string NOT_IMPLEMENTED.

mvf-tech/system_logger 适用场景与选型建议

mvf-tech/system_logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.19k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mvf-tech/system_logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mvf-tech/system_logger 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 10.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-27