3

I have a ruby application (not Rails) using Resque. I'd like to know what's going on in one of the worker I have.

To do that, I use the Logger class as stated in the officiel documentation.

Below is how I log inside a worker:

require 'resque'
require 'logger'

<code>

Resque.logger = Logger.new File.new('logfile.log', 'a')
Resque.logger.info "Whatever"

However, when running my worker, nothing is actually being logged. It's as if the worker is actually ignoring all those log instructions. No error is raised. The other pieces of code actually work - only the logging part is ignored.

I tried to use the logger class itself (ie logger = Logger.new) but the result is the same.

Do you have any idea on how I can actually log something inside my resque worker?

Thanks!

henritroyat
  • 201
  • 2
  • 14

3 Answers3

1

Use the following:

Logger.new(path_to_log_file).info(anything)
bummi
  • 27,123
  • 14
  • 62
  • 101
SHS
  • 7,651
  • 3
  • 18
  • 28
1

You are missing the log level to enabled printing info logs, according to the documentation you linked there, you can use something like this

Resque.logger.level = Logger::DEBUG

then if you look into Logger docs it lists levels as

DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN

so if you are using logger.info you either need Logger::DEBUG or Logger::INFO to have the logged string to show up.

Also make sure the logger initialization is run by the process running the workers, and not just the process enqueueing jobs.

rafb3
  • 1,694
  • 12
  • 12
  • For the last couple of days, I tried almost all techniques I could find on internet, including yours. Simply nothing happens. I don't have any errors with what you wrote, however nothing is being logged at all. I really don't get it. – henritroyat Dec 17 '14 at 22:57
  • 1
    @henritroyat then you probably need `VERBOSE=1` set on your env – rafb3 Dec 17 '14 at 23:30
0

my environment: rails 5.0.1, resque: 1.26.0.

I tried config the resque logger in config/initializers/resque.rb and lib/tasks/resuqe.rake, they neither work for me.

but config the resque logger inside every job, that works for me, although it is not perfect.

# update_xxx_job.rb
class UpdateXxxJob
  def self.perform
    Resque.logger = Logger.new("#{Rails.root}/log/resque.log")
    Resque.logger.level = Logger::DEBUG   

    Resque.logger.info 'Job starts'
    ...
  end
end

more details in another answer.

Spark.Bao
  • 5,573
  • 2
  • 31
  • 36