Level 75
Add this to your app\Exceptions\Handler.php
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Support\Facades\Log;
use Request;
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
if ($exception instanceof ModelNotFoundException || $exception instanceof NotFoundHttpException) {
$url = Request::fullUrl();
Log::info("404 in {$url}");
}
return parent::render($request, $exception);
}
/**
* Get the default context variables for logging.
*
* @return array
*/
protected function context()
{
try {
$context = array_filter([
'url' => Request::fullUrl(),
'input' => Request::except(['password', 'password_confirmation'])
]);
} catch (Throwable $e) {
$context = [];
}
return array_merge($context, parent::context());
}
The context method is useful if you want to store additional informations for all errors in the log file.
1 like