How to Install Laravel LogViewer Package

LogViewer is a package for Laravel framework which allows developers to manage and keep track of all log files in a user-friendly manner and in this tutorial we will see how to install and configure it.

You can easily install LogViewer by Composer with the following command:

$ composer require arcanedev/log-viewer:5.0.*

At the time of writing this tutorial, LogViewer supports just the daily log channel. So the first step after installing it, is to open .env file in the root of the project and change the LOG_CHANNEL key as follows:

LOG_CHANNEL=daily

To empty the cache in order to make changes effect, we need to run the following command:

$ php artisan config:cache

To publish the config and translation files, run this command:

$ php artisan log-viewer:publish

For clearing all generated log files, you can run the following command:

$ php artisan log-viewer:clear

Now, you can go to http://project-name/log-viewer and see the dashboard of LogViewer.

Generally speaking, logs are not supposed to be seen by unauthorized users. So we need to make some changes in the configuration of the package to limit access to it. To do that, open the log-viewer.php file inside config folder:

 route  => [
     enabled  => true,
     attributes  => [
         prefix  =>  dashboard/log-viewer ,
         middleware  => ['web','aut']
    ]
]

The prefix key is changed from log-viewer to dashboard/log-viewer in order to be meaningful in such a way that only logged in users can go to this route but it's not enough. The next key called middleware is where we can limit access to all the following routes which are related to this package:

dashboard/log-viewer                            
dashboard/log-viewer/logs                       
dashboard/log-viewer/logs/delete               
dashboard/log-viewer/logs/{date}                
dashboard/log-viewer/logs/{date}/download       
dashboard/log-viewer/logs/{date}/{level}        
dashboard/log-viewer/logs/{date}/{level}/search

In order to add the auth Middleware that comes with Laravel, we need to add ['web', 'auth'] as the value of middleware key. From now on, just logged in users can access the dashboard of LogViewer.

by Behzad Moradi on 2019-08-10