定制 parli/json-logger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

parli/json-logger

Composer 安装命令:

composer require parli/json-logger

包简介

PSR-3 JSON logger

README 文档

README

A PSR-3 JSON log formatter. This outputs a format designed around Datadog's logging system, using their predefined attributes for the structure.

Usage

This library only formats logs, and does not write them. It must be used in conjunction with another PSR-3 which actually writes the logs somewhere useful. (For us, this is stdout due to deployment in a containerized environment.)

$writer = new \SomePsr3Logger();
$logger = new \Parli\JsonLogger\JsonLogger($writer);
// ...
$logger->error('Error message {info}', [
    'info' => $someMoreInfo,
    'exception' => $someThrowable,
]);

Note: the log writer will not receive the $context that this library receives. This library interpolates the context into the JSON message before passing a fully-formatted JSON string to the log writer.

Exception logging

This library looks for Throwables in the exception key of $context, per PSR-3 section 1.3. If found, it will automatically fill in the error attributes for integration with Datadog's log display system.

It is RECOMMENDED that you always pass caught exceptions to the logger's $context (e.g. ->error('...', ['exception' => $e])). It is further RECOMMENDED that you do not do additional log interpolation.

Example:

try {
    // ...
} catch (Throwable $e) {
    $logger->error('Caught exception in worker with input {input}', [
        'input' => $input,
        'exception' => $e,
    ]);
}

COUNTEREXAMPLE:

// Do NOT do this:
try {
    // ...
} catch (Throwable $e) {
    $logger->error('Caught exception in worker with input {input} - {message}: {trace}', [
        'input' => $input,
        'message' => $e->getMessage(),
        'trace' => $e->getTraceAsString(),
        'exception' => $e,
    ]);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固