This article gives you brief about Log Monitoring in Laravel and how to get your logs to view pages via Log-Viewer package.
So If you are here wondering why would you need to monitor your logs on view pages consider an example :
So you have created a excellent web application, and one of your client’s reports you that on doing a particular action he gets “Whoops, looks like something went wrong.” . You now have to check logs, for that you need to SSH into your production server and open your log file and check what exactly went wrong.
Log-viewer package will do the same for you, instead you can just go to your log-viewer url and quickly check the latest error messages in the log file.
Apart from this you can use log-viewer screen to monitor how your user’s are interacting with the application and immediately see if something is going wrong with your application.
Alright, Let’s dig into the Installation of Package
Requirement
LogViewer support only the daily log channel, so make sure that the LOG_CHANNEL
is set to daily
instead of stack
in your .env
file.
For Laravel 5.5 and below, set this in your .env
file
APP_LOG=daily
Installation Of LogViewer Package
We will be installing ARCANEDEV LogViewer package for the log monitoring.
Let’s install the LogViewer composer package. I am using installing it on my Laravel 5.6 project.
Navigate to your project root folder and run the following composer command.
composer require arcanedev/log-viewer
This should install the arcanedev/log-viewer package, and give following result on command line
Setup
Once the package is installed, you can register the service provider in config/app.php
in the providers
array:
'providers' => [ ... Arcanedev\LogViewer\LogViewerServiceProvider::class, ],
No need to register the LogViewer facade, it’s done automatically.
Next, To publish the config and translations files, run this command:
php artisan log-viewer:publish
Navigate to http://your-project-url/log-viewer you can should see a nice dashboard to monitor your logs.
Configuration
Following are some further configuration tips on the package.
If you are looking to change the default url of log-viewer then go to config/log-viewer.php and change the prefix
attribute
'route' => [ 'enabled' => true, 'attributes' => [ 'prefix' => '/something/log-monitor', 'middleware' => env('ARCANEDEV_LOGVIEWER_MIDDLEWARE') ? explode(',', env('ARCANEDEV_LOGVIEWER_MIDDLEWARE')) : null, ], ],
If you want your log-viewer to be seen only by authenticated users then set the ARCANEDEV_LOGVIEWER_MIDDLEWARE
property in your project .env
file.
ARCANEDEV_LOGVIEWER_MIDDLEWARE=auth
That’s it ! Have fun Monitoring Laravel Logs