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

Setup:


Requirement:
  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
Start:
  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

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. You have some mistakes I think. You have not included package.json file so I am not able t o run npm install. And if I follow all steps but skill this, I get this error: "Error: Cannot find module 'gulp-notify'" even tough gulp is installed.

    ReplyDelete
  3. I installed gulp-notify and gulp-intercept and it fixed it. So please either update package.json file or add these commands in your posts.

    ReplyDelete
    Replies
    1. Sorry, I have uploaded package.json file in the repo.

      Thank you for pointing out.

      Delete