Hello everyone, welcome back at porkaone. On this occasion, we will learn how to display a list of error messages or error logs in Laravel. Come on, follow in full below!
By default, Laravel saves application logs in the file
storage/logs/laravavel.log. So every time an error or exception
occurs it will be recorded in the file. The problem is, when the application
has been deployed or published on the internet, it will be difficult for us
to see the errors that occur. When an error occurs, Laravel will only
display the words 550 | server error only. To overcome the errors that
occur, we can use the packages available in Laravel.
How to Display Error Log List in Laravel
1. Prepare a Laravel project, you can use Laravel version 6,7,8,9 and so on. You can use an existing project or install a new laravel project.2. Next, we will install the laravel log viewer package. Please enter into your laravel directory respectively. Then open cmd or terminal and run the command below.
composer require rap2hpoutre/laravel-log-viewer:2.2.0
3. After the installation process is complete, please run the command below.
php artisan vendor:publish
4. Next a display will appear like the image below. Then enter the number 9
5. After the above process is complete. Open config/app.php in the providers edit section as below.
'providers' => [
...
Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class, //add this script
],
6. Next, open the routes/web.php file. Then add a new route.
Route::get('log-viewers', [\Rap2hpoutre\LaravelLogViewer\LogViewerController::class, 'index']);
We have done all the stages, now it's time to do a trial run. Please run the php artisan serve command. Then access http://localhost:8000/log-viewers. If successful, it will look like the one below.
Log Viewers |
The image above is an example of an error that occurs during the process
of using the application. And if published on the internet, you can
protect this route with authentication so that only certain users can view
the error logs that occur.
Ok, that's all for this tutorial about how to display log lists in
Laravel. Hopefully this short tutorial can be useful and can be
implemented. If you have questions, please ask directly in the comments
column below. That is all and thank you.
0 Comments
Come on ask us and let's discuss together
Emoji