Laravel 10 log Tutorial

Laravel Log

Laravel 10 log viewer, in this article we will see step by step the error log in an application with the Laravel framework

Log Tutorial

The first step in error logging is to add the class to our controller, so we add the following class

use Illuminate\Support\Facades\Log;

This would be the class that comes from the Laravel core in the vendor folder using composer

class Log extends Facade
    protected static function getFacadeAccessor()
        return 'log';

Then we create a method and add the following code, remember first to connect your database either with mysql or postgresql and load some test records with the faker library

public function transaction(User $user, $token, $id)

        $transactions = $user::with('transactions')->findOrFail($id);


        return $this->successResponse($transactions);   


Log File – Example

Where we will use the debug method of the log class to obtain the result of a transaction, and it will simply show us the information in timestamp format in the storage/logs/laravel.log path

Laravel Log File

Log Error – Example

Remember to always import the class at the top of the controller so that no errors occur in our application, and in simple steps we have a working application