Thursday, 10 March 2016

Apache Error notifier using Gulp

I wanted an easy way to retrieve critical errors from my Apache error log. While i was finding a solution, Gulp came into the picture. First let me introduce you to Gulp.

Gulp is a build system which you can use to automate your tasks. Its same as Grunt if you have heard of it.

I have used Gulp to automate following tasks in past:
  1. Compiling SCSS 
  2. Compressing CSS
  3. Auto reloading my browser if CSS changes.
  4. Compiling Coffeescripts
Now it was time to use gulp for Apache notification. So I created Gulp task for the same. Here is the script.

First of all I have included 3 Gulp dependencies which is Gulp itself as i don't have gulp in my environment, Gulp notifier to display error notification and Gulp Intercept to Go through log file and retrieve the error.

I have defined Watch as default task. Default task is a task which Gulp keep running continuously. The task keep watching over the log file. Whenever the error log file changes, Task will go through the file and will retrieve recent errors and will display them.

The script will display mainly 2 types of critical errors:

  1. PHP Fatal Error
  2. PHP Parse Error


  1. Node
Installation Steps:
  1. First setup Node.
  2. Install Gulp
  3. Then clone this repository. Or Download repository from Github.
  4. Run npm install
  1. Goto the cloned repository.
  2. First add path to your Apache's Php Error log file in variable "logPath". (Default is /var/log/apache2/error.log)
  3. Run sudo gulp