Resque jobs are just plain old ruby objects. I can use puts
calls inside them to produce output into the console, or I can instantiate a standard Ruby Logger
class with STDOUT
and use that.
But is开发者_开发百科 there a correct approach to logging in Rails, from places that aren't controllers or models? I see Rails.logger
returns a BufferedLogger
, but when I call info
or warn
etc on it, nothing happens. If I call flush
on it, it just returns an empty array and nothing is output.
What's the convention here?
I'm not really sure that there is a convention. I had a pretty ugly logging system up until just recently. Now I use lumber to integrate log4r with Rails. That really made logging much nicer because I now have named loggers (e.g., logger matches the class name -- great for filtering output) and I can control log levels on a per-logger (i.e., per-class) basis.
There's also a GELF adapter for log4r if you want to use graylog2 to aggregate your logs.
精彩评论