Skip to content

Laravel 11 how to catch all error to log (including default in dontReport) #52271

Answered by adeiming
adeiming asked this question in Q&A
Discussion options

You must be logged in to vote

Actually I have solved it, just changed report() to render()

->withExceptions(function (Exceptions $exceptions) {
        $exceptions->render(function (Exception $e) { <--- report to render
            $data = [
                'method' => request()->getMethod(),
                'message' => $e->getMessage(),
                'user' => auth()->id(),
                'data' => request()->all(),
            ];
    
            if ($e instanceof ValidationException) {
                $data['errors'] = $e->errors();
            }
    
            Log::channel('daily')->info(json_encode($data, JSON_PRETTY_PRINT));      
        });
    })

Remember my problem, all errors other than status code 20…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@adeiming
Comment options

@henzeb
Comment options

@adeiming
Comment options

Comment options

You must be logged in to vote
4 replies
@adeiming
Comment options

@nafaarts
Comment options

@adeiming
Comment options

@adeiming
Comment options

Answer selected by adeiming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants