Simple Laravel Log Monitoring Using

Guys, have you ever encountered a situation when your application crashed in production? Of course you have. All you gonna do is to look for the cause through your log files. Log file records every events that occur in your application. In this case, error log is your log file. But, in order see the log file, we need to login into the server and read the log manually. That’s really not worthy.


To make this kind of job easier, we need to create a log monitoring system for our apps. So you don’t need to read your log file in each server manually to find the root cause. Why we need log monitoring? By using log monitoring, we can see all log file from all of our systems in a centralized place and in a convenient way. Also you can do log analysis and reporting though this system.


This tutorial will guide you how to implement simple log monitoring system. In tutorial, I will use as a monitoring tool for laravel project. in a monitoring tool which is backed by node.js and consists of two service, i.e. server and harvester. Harvester watch for every changes that happened in log files listed in harvester configuration file and send them to server. Then server will listen any messages sent from harvester and broadcast them to client/browser. Harvester send the messages via TCP protocol to server.



These are the requirements that you will need in this tutorial:

  • NVM (Node Version Manager, optional)
  • js (I use node.js version 4.4.3)
  • Laravel project (I use laravel 5.2)
  • io (as a node.js package)



I suppose you have installed node.js on you system. So our next step is to install via NPM. NPM is a javascript package manager. It’s the same like composer for PHP, gem for ruby, and pip for python. Install to your system by typing this via terminal:

sudo npm install -g –user “alvin”


-g means install as a global package and –user “alvin” as a specific user (alvin is a current user). Now move to configuration directory and you will see there are three configuration files.


Now open your harvester.conf file and edit the file according to your applications which you are going to monitor their log.


Put your application log path in logStream section so the harvester will watch every log files listed there. You can list as many project & log file as you want. After you edit the file, you can run these two services in different terminal:

  • io-server
  • io-harvester


Browse to http://localhost:28778 to open web interface. Now I will simulate how works. I will create a page which error occurs and open it.


And all information from the error log should been seen in web interface.


Monitor laravel daily log file

Laravel allow you split your log into daily log files instead of single log file. The advantages of using daily log files are log easy to manage and it can avoid single huge log file. To configure laravel into daily log file, open config/app.php file and change log section into daily log. You can also add log configuration via .env file.


After your configuration has been changed, everytime an error occurs, laravel will insert log into daily log file based on this pattern laravel-yyyy-mm-dd.log.


In order to allow read log file based on this pattern, we need to modify harvester.conf file by using some javascript code (since is built by javascript) into this one.


After that, you need to restart harvester service to enable this changes. Now, every laravel log with current date format will be read by harvester.

Note: you need to restart your harvester service every midnight in order to read current date (probably every 00:00 AM).


Modify to read only some lines of laravel log messages

If you look in detail, once an error occurs happened, laravel would produce a lot of error log messages which is about 40 lines. Unfortunately, not all of those messages are important for developer to trace an error. Some programmers only need several lines of message in order find error and fix it (I personally only look up to first 4 or 6 lines of error messages).

So, how to make to show only some lines of error messages? To do that, we need to make some changes to main code.

Note: you may only do this if you use only for monitoring one type of application (ex: only for laravel application). Different type of application will produce different log format. Use different if apply this step for different application.


First, you need to locate harvester.js which is main library file for harvesting log message process. Since I’m using NVM and node.js version 4.4.3, this file is located in ~/.nvm/versions/node/v4.4.3/lib/node_modules/ If you are not using NVM, this file should be located in your main node.js library directory. Open the file and find a piece of code like this.


This piece of code is responsible to read every log messages that are written to log file. We will modify this code. We need to declare how much lines will be read and put it into for loop code. Now, let’s modify the code into this one.


You can specify how many lines will be read by changing the value of numOfLines variable. Now restart your server and harvester to enable this changes. After that, the log messages which is displayed in browser will be as many as you specified in harvester.js file.


Although is not a new log monitoring system, it’s still a good tool to monitor your log file in a real time, so you don’t need to check to every server just to look for the root cause whenever your apps werte crashed in production. For more information about, you can visit this website





You Might Also Like

No Comment

Leave your thought