Immediate log messages of resque workers

The following description and code example was tested with the following gem spec:

Since the default Resque.logger does not immediately flush all log messages to the log file, we want to use our own logger instance and a separate log file. All we have to do are the following steps:

  1. If you do not have a resque.rake rake file then go ahead and create one in your lib/tasks folder.
  2. To initialize a new logger we will use the Resque.before_fork hook inside the setup task.
  3. Open a new log file in your preferred location and activate the synchronization flag to avoid block buffering.
  4. Create a new instance of ActiveResource::BufferedLogger and set it as the default Resque.logger.
  5. Set the appropriate log level for your needs.
  6. That’s it!

The complete code will be show below.