laravel5.7 不记录 sql 报错日志,自定义日志信息
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 协议》,转载必须注明作者和本文链接
推荐文章: