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()
|
|
|
|
|
{
|
|
|
|
|
$format = "[%datetime%] [" . REQUEST_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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|