这是一个将 curtisdf 的答案与 Seldaek 的答案相结合的解决方案,并且不需要子类化 Monolog的LineFormatter
。
假设您的app/start/global.php
文件包含:
Log::useFiles(storage_path() . '/logs/laravel.log');
将其替换为:
use Monolog\Handler\StreamHandler;
use Monolog\Logger as MonologLogger;
use Monolog\Formatter\LineFormatter;
// Use custom LineFormatter, with ignoreEmptyContextAndExtra enabled
Log::getMonolog()->pushHandler(
(new StreamHandler(
storage_path() . '/logs/laravel.log',
MonologLogger::DEBUG
))->setFormatter(new LineFormatter(null, null, true, true))
);