Laravel 版本:5.4.25 PHP 版本:7.0
在 Laravel 的早期版本中,有一个ConfigureLogging 类来执行此操作。但在 Laravel 的最新版本中,该类被删除,而是有一个新的 LogServiceProvider:
protected function configureDailyHandler(Application $app, Writer $log)
{
$log->useDailyFiles(
$app->storagePath() . '/logs/customLogName.log',
$app->make('config')->get('app.log_max_files', 5)
);
}
Run Code Online (Sandbox Code Playgroud)
我想重写这个方法。
我怎样才能做到这一点 ?
请帮忙。
谢谢。
终于我明白了。
app/bootstrap/app.php返回实例后将其添加到您的文件中$app:
$app->configureMonologUsing(function($monolog) use ($app) {
$monolog->pushHandler(
(new Monolog\Handler\RotatingFileHandler(
// Set the log path
$app->storagePath().'/logs/customLogName.log',
// Set the number of daily files you want to keep
$app->make('config')->get('app.log_max_files', 5)
))->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true))
);
});
return $app;
Run Code Online (Sandbox Code Playgroud)
就可以了