Logging resque with monolog

PHP-Resque is a php library for creating workers that will execute background jobs using a redis queue. It is a port of the Resque Ruby library developed by Github and stores the data on redis using the exact same data format. The library is logging to STDOUT and has the "VERBOSE" and "VVERBOSE" settings to choose between basic and detailed information. There is also an event/hook system that allows for a more custom logging solution.

The PHP-Resque-Log library is a plugin for resque to log the workers execution using the Monolog library. Monolog supports different loggers and provides an easy way to switch between loggers.

Using php-resque-log is very simple, an "init" function needs to be called with the logger passed as a parameter.

ResqueLog\Plugin::init([
  'logger'         => $log,
  'vverbose'       => true,
  'queueSizeLimit' => 100,
]);

An event will be logged when:

  • a new worker starts
  • a job is added to the queue, prepared for execution and successfully performed or when a job throws an exception
  • a fork is about to be created for a job and when one is created

The plugin will also monitor the queue size and log a warning when it is greater than a defined max value queueSizeLimit

Follow me for updates on similar new posts I write or tweet about this post.