重写report优雅记录

This commit is contained in:
kuaifan 2021-12-10 10:29:09 +08:00
parent 7ef966536d
commit a303a60c4e

View File

@ -5,6 +5,7 @@ namespace App\Exceptions;
use App\Module\Base; use App\Module\Base;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Log;
use Throwable; use Throwable;
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
@ -57,4 +58,18 @@ class Handler extends ExceptionHandler
} }
return parent::render($request, $e); return parent::render($request, $e);
} }
/**
* 重写report优雅记录
* @param Throwable $e
* @throws Throwable
*/
public function report(Throwable $e)
{
if ($e instanceof ApiException) {
Log::error($e->getMessage(), ['exception' => ' at ' . $e->getFile() .':' . $e->getLine()]);
} else {
parent::report($e);
}
}
} }