Laravel日志文档:https://laravel.com/docs/10.x/logging
把错误信息写入日志
\Log::error('系统异常', ['exception' => $this->exception]);
把执行的SQL写入日志
把一些代码添加到这个文件内即可:app\Providers\AppServiceProvider.php
public function boot()
{
Schema::defaultStringLength(191);
// 添加一些代码
\DB::listen(function($query) {
$tmp = str_replace('?', '"'.'%s'.'"', $query->sql);
$tmp = vsprintf($tmp, $query->bindings);
$tmp = str_replace("\\","",$tmp);
\Log::info(' execution time: '.$query->time.'ms; '.$tmp."\n\n\t");
});
}