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
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-04