To ensure the stability and functionality of your online application, efficient logging and monitoring are required. Laravel 10, a popular PHP framework, provides developers with a robust tool called “LogViewer” that provides a visually beautiful and user-friendly interface for viewing and analysing logs from your application.
LogViewer makes it easier to track mistakes, fix problems, and obtain useful insights into the behaviour of your programme.
Read More: Laravel 10 Telescope: Debugging and Monitoring Tool
In this tutorial, we’ll show you how to use LogViewer in Laravel 10, a beautiful log viewer package that improves debugging and monitoring. We’ll walk you through the installation procedure, go through its capabilities, and show you how to use LogViewer to streamline your development workflow.
Let’s get started.
Laravel Installation
Open terminal and run this command to create a laravel project.
composer create-project laravel/laravel myblog
It will create a project folder with name myblog inside your local system.
To start the development server of laravel –
php artisan serve
URL: http://127.0.0.1:8000
Assuming laravel already installed inside your system.
What is LogViewer Package of Laravel?
Log files are vital in Laravel for diagnosing problems, monitoring application behaviour, and obtaining insights into how the application works. The LogViewer package is a third-party Laravel package meant to make reading and analysing log files easier.
It provides a user-friendly interface for developers to explore log entries, search for relevant information, and successfully troubleshoot issues.
Key Features of the Laravel LogViewer Package:
- Log File Management
- User-Friendly Interface
- Search and Filtering
- Highlighting and Formatting
- Log Levels
- Download and Export
LogViewer: Package Installation
Open project into terminal and run this composer command,
$ composer require arcanedev/log-viewer
It will install package into application.
Read More: Laravel 10 Working with MySQL Joins Example
Once installation done, you must see a commands list of LogViewer in artisan command panel.
Open .env file and this line into it.
LOG_CHANNEL=daily
LogViewer: Generate Scaffolding Files
LogViewer composer package generates layout file, css file, config file etc. These all are the scaffolding files to make it working with great UI.
Open terminal and run this command.
Publish the Config and Translations Files
$ php artisan log-viewer:publish
If you are not able to publish files, you can publish it forcefully.
$ php artisan log-viewer:publish --force
Publishing the config only
$ php artisan log-viewer:publish --tag=config
Read More: Laravel 10 Seed Database Using Faker Library Tutorial
Application requirements & log files check
$ php artisan log-viewer:check
Everything is done! Great 🙂
Application Testing
Run this command into project terminal to start development server,
php artisan serve
URL: http://127.0.0.1:8000/log-viewer
Log-viewer dashboard view when there is no log available in application.
Unit Testing: Create Logs
Let’s add some test logs in application to test this log-viewer dashboard.
Open web.php file from /routes folder. Add these code into it.
//... use Illuminate\Support\Facades\Log; //... Route::get("log-message", function () { $message = "This is a sample message for Test."; Log::emergency($message); Log::alert($message); Log::critical($message); Log::error($message); Log::warning($message); Log::notice($message); Log::info($message); Log::debug($message); }); //...
Open URL into browser to hit this method.
URL - http://127.0.0.1:8000/log-message
Read More: Laravel 10 How To Setup Ajax Request Tutorial
This will create a log file. Log file will be created inside /storage/logs with name like laravel-xxx-xxx-xxx.log.
Inside log file, data will be like.
[2023-08-20 04:39:32] local.EMERGENCY: This is a sample message for Test.
[2023-08-20 04:39:32] local.ALERT: This is a sample message for Test.
[2023-08-20 04:39:32] local.CRITICAL: This is a sample message for Test.
[2023-08-20 04:39:32] local.ERROR: This is a sample message for Test.
[2023-08-20 04:39:32] local.WARNING: This is a sample message for Test.
[2023-08-20 04:39:32] local.NOTICE: This is a sample message for Test.
[2023-08-20 04:39:32] local.INFO: This is a sample message for Test.
[2023-08-20 04:39:32] local.DEBUG: This is a sample message for Test.
In this case you should see log-viewer dashboard as,
Logs Table
Single Log Detail
When we click on any log, it will open a single log detail page.
We hope this article helped you to learn about Laravel 10 LogViewer: A Beautiful Log Viewer Tutorial in a very detailed way.
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.