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
- 3.0.0 - Patch Notes
- 2.1.0 - Patch Notes
- 2.0.2 - Patch Notes
- 2.0.1 - Patch Notes
- 2.0.0 - Patch Notes
- 1.0.0
Installation and Setup
- Run
composer require mvf-tech/system_loggerto install the package - You will also have to set
DATADOG_PROJECT_NAMEandDATADOG_SERVICE_NAMEENV 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,warningorerrorone 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
:0would not be replaced sinceCommandLineimplementsHostLogInterfaceand 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:tagsarray 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 stringNOT_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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-27