update 2010/10/16: RAILS_DEFAULT_LOGGER is deprecated. I’m using ActiveRecord::Base.logger now as in:
ActiveRecord::Base.logger.debug "value of x is #{x}"
read on for the older solution…
I just spent five minutes figuring out how to log from a model class in Rails (or any class that isn’t a controller or view). Y’see, there is no “logger” method on an ActiveRecord for instance. Once again Robby to the rescue with an oblique mention of the RAILS_DEFAULT_LOGGER global. I love that guy.
Related: I wonder what Jamis circa ’05 was talking about when he said:
Note: logging is a bad example here, because Rails already has very good support for logging. Furthermore, recent Rails releases support a service keyword, for declaring and using system-global services in the same manner described here.
Huh? Service keyword?
re: service keyword
I’m not sure what he was talking about either.
However, The RAILS_DEFAULT_LOGGER is quite handy sometimes. :-)
Thanks for the tip. It helped me isolate a performance problem to a single line of code in a model by logging.