Laravel 默认不报告这些:
//src/Illuminate/Foundation/Exceptions/Handler.php
/**
* A list of the internal exception types that should not be reported.
*
* @var array
*/
protected $internalDontReport = [
AuthenticationException::class,
AuthorizationException::class,
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
SuspiciousOperationException::class,
TokenMismatchException::class,
ValidationException::class,
];
现在,您可以在 app/Exceptions/Handler.php 中导入该数组,然后删除 HttpException 和 ModelNotFoundException,或者您想要的任何异常
...
// app/Exceptions/Handler.php
protected $internalDontReport = [
AuthenticationException::class,
AuthorizationException::class,
// HttpException::class,
HttpResponseException::class,
// ModelNotFoundException::class,
SuspiciousOperationException::class,
TokenMismatchException::class,
ValidationException::class,
];
...
ModelNotFoundException 是当你有类似route::get('/articles/{article}','ArticleController@single'); 的路线时
并在控制器中分配为 function single(Article $article) 和 $article 未找到。
选择要保留的内容和要注释掉的内容。
第二种方法是在同一 Handler.php 文件中的 report 方法中执行此操作
/**
* Report or log an exception.
*
* @param \Exception $exception
*
* @return void
* @throws Exception
*/
public function report(Exception $exception)
{
# Report 404
if ($exception instanceof NotFoundHttpException || $exception instanceof ModelNotFoundException) {
# Log as warning
Log::warning('Your message');
# Or Log as info
Log::info($exception);
// ...
}
....
}
您可以在此Laravel Logging 中找到有关登录的更多信息
还有Laravel Errors
希望这能回答你的问题!