Immediate log messages of resque workers

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

rails (3.2.11)
resque (1.24.1)
resque-scheduler (2.0.1)

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.

require "resque/tasks"
require 'resque_scheduler/tasks'

task "resque:setup" => :environment do
  Resque.before_fork = { 

    # Open the new separate log file
    logfile =, 'log', 'resque.log'), 'a')

    # Activate file synchronization
    logfile.sync = true

    # Create a new buffered logger
    Resque.logger =
    Resque.logger.level = Logger::INFO "Resque Logger Initialized!"