How to log the exception in Laravel | Exception handling in Laravel

This tutorial is to learn how to handle and log the exceptions in Laravel. We will simply use try & catch to handle the exceptions in Laravel.

This is always good practice to handle the exceptions in any application to track the issue.

Laravel provides the following library to log the exceptions.

Now I'll demo the code to catch the exception and log it.

Here I have defined UserServiceProvider class and inside this class deleteUser() is a function to delete the user.

So here in catch part we are logging the exception.

Laravel also provides facality to log the basic information like below code.

In Laravel logs are stored in storage/logs directory.

You also can create the log on daily basis in Laravel by following steps:

open app.php which is inside the config directory.

Change single to daily like below.

 

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *