laravel5.7 不記錄 sql 報錯日誌,自定義日誌資訊

php_yt發表於2021-12-13

laravel 5.7

app/Handler.php

use Illuminate\Database\QueryException;

protected $dontReport = [
    //不記錄日誌
   QueryException::class,
];

public function report(Exception $exception)
{
    //自定義輸出日誌
    if ($exception instanceof QueryException) {
       // \Log::error($exception->getPrevious()->getMessage()); //@1
       \Log::error($exception->getMessage());//@2
    }
    parent::report($exception);
}

@1

SQLSTATE[HY000] [2002] Connection timed out

@2

SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from `fields` limit 1)
本作品採用《CC 協議》,轉載必須註明作者和本文連結
focus

相關文章