macbre/monolog-utils
最新稳定版本:3.1.0
Composer 安装命令:
composer require macbre/monolog-utils
包简介
Additional formatters and processors for Monolog
README 文档
README
Additional formatters and processors for Monolog 3.x. This package requires PHP 8.1+.
ExceptionProcessor
Allows you to pass an Exception instance as a part of $context - it will be automatically expanded to log exception class, message, code and a backtrace
try { // do something } catch (NastyException $ex) { $logger->error('Something bad happended', [ 'exception' => $ex ]); }
exception field will be expanded to something similar to:
{
"context": {
"exception": {
"class": "NastyException",
"message": "Things went wrong",
"code": 42,
"trace": [
"/home/macbre/app/Foo.class.php:979",
"/home/macbre/app/App.class.php:29",
"/home/macbre/app/index.php:18"
]
}
}
}
RequestIdProcessor
Automatically generates a unique, per request ID that is sent with every message log as request_id field in $extra.
JsonFormatter
JSON log formatter for elastic / Kibana.
An example entry:
$logger->error('Foo Bar', [ 'size' => 42 ]);
{
"@timestamp": "2023-04-18T08:25:23.123456+00:00",
"message": "Foo Bar",
"context": {
"size": 42
},
"extra": {
"request_id": "566c04c2f22693.59900054"
},
"severity": "error",
"channel": "my.app",
"source_host": "my.server.net"
}
Example
$logger = new Monolog\Logger('my.app'); $logger->pushProcessor(new Macbre\Logger\Processors\ExceptionProcessor()); $logger->pushProcessor(new Macbre\Logger\Processors\RequestIdProcessor()); // Syslog and JSON formatter for elastic / Kibana $syslog = new Monolog\Handler\SyslogUdpHandler('127.0.0.1', 514, LOG_USER, Monolog\Logger::INFO); $syslog->setFormatter(new Macbre\Logger\Formatters\JsonFormatter()); $logger->pushHandler($syslog); // and now let's use the logger... $logger->error('Foo Bar', [ 'exception' => new Exception('An error', 123), 'size' => 42 ]);
统计信息
- 总下载量: 11.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-12