From a303a60c4e685e44d5a21a2b45dccd0b2a78dd5a Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 10 Dec 2021 10:29:09 +0800 Subject: [PATCH] =?UTF-8?q?=20=E9=87=8D=E5=86=99report=E4=BC=98=E9=9B=85?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exceptions/Handler.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7c52374bb..e17af7d63 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -5,6 +5,7 @@ use App\Module\Base; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Support\Facades\Log; use Throwable; class Handler extends ExceptionHandler @@ -57,4 +58,18 @@ public function render($request, Throwable $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); + } + } }