normalize-logging

This commit is contained in:
xiaomlove
2021-04-26 20:37:17 +08:00
parent 58c6aa58e8
commit 63a2c71cb6
18 changed files with 225 additions and 109 deletions

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Logging;
use Monolog\Formatter\LineFormatter;
class NexusFormatter
{
public function __invoke($logger)
{
foreach ($logger->getHandlers() as $handler) {
$handler->setFormatter($this->formatter());
}
}
protected function formatter()
{
$format = "[%datetime%] [" . REQUEST_ID . "] %channel%.%level_name%: %message% %context% %extra%\n";
return tap(new LineFormatter($format, null, true, true), function ($formatter) {
$formatter->includeStacktraces();
});
}
}