mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
28 lines
715 B
PHP
28 lines
715 B
PHP
<?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()
|
|
{
|
|
$id = 'NO_REQUEST_ID';
|
|
if (nexus()) {
|
|
$id = nexus()->getRequestId();
|
|
}
|
|
$id .= " -> " . getLogFile();
|
|
$format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n";
|
|
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
|
|
$formatter->includeStacktraces();
|
|
});
|
|
}
|
|
}
|