Files
nexusphp/app/Logging/NexusFormatter.php

27 lines
677 B
PHP
Raw Normal View History

2021-04-26 20:37:17 +08:00
<?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()
{
2022-04-17 16:38:44 +08:00
$id = 'NO_REQUEST_ID';
if (nexus()) {
$id = nexus()->getRequestId();
}
$format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n";
2021-04-26 20:51:41 +08:00
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
2021-04-26 20:37:17 +08:00
$formatter->includeStacktraces();
});
}
}