Laravel Log Viewer - View logs in a GUI

Introduction

When working on Laravel checking the log file can be a pain as the logs don’t appear clear and it sometimes can be difficult to view the full log when viewing it in the code editor.

There is a popular package called Log Viewer that can be installed on your project and allows you to view the logs through a GUI instead of having to view the log file directly.

Also, this would come in handy for apps hosted on servers as it makes it easier to view logs rather than having to go through the process of connecting to a web server and viewing the log file through a terminal.

log-viewer-site.png

How to install

Open up the terminal and change the directory to where the Laravel project is located.

Use composer to install the log viewer composer package.

composer require opcodesio/log-viewer

To set up the view files use the following command.

php artisan log-viewer:publish

How to use

Start up the Laravel project using the artisan serve command.

php artisan serve

Once the site is up and running go to the log-viewer path at…

http://localhost:8000/log-viewer

You will see a page with no log showing because you will need to select the log file you want to view.

Important Note: This page won’t show on production as the APP_ENV environment variable gets checked.

Left-click on the log file you want to view in the left menu as shown below.

log-list.png

The logs will load and show up in the list view, here is an example of logs from an app that I use.

The blank exceptions are due to me adding a custom exception handler but typically you will see the exception messages.

log-viewer-page-2.png

How to configure

A config file isn’t added by default as it’s not required to use the log viewer; to add it, use the following command.

php artisan vendor:publish --tag="log-viewer-config"

Conclusion

I’m going to use this for local development and set this up to be available for production however I need to implement authentication before this change can be added,

For the ease of using a web page to view the logs and not viewing the text file makes a big difference coupled with the fact that the logs can be filtered by type.

I highly recommend using this plugin for your Laravel apps.