Using the Rails logger outside of models and controllers

You can use the Rails logger outside of Rails models in at least version 2.3.X and up of Rails. You might be used to doing the following in your models or controllers:

logger.info "Some debugging info I want to see in my development log."

If you make a regular model that doesn’t inherit from ActiveRecord, though, you may see the following error:

undefined local variable or method `logger' for #<Class:0x42fd77c>

The solution is to call Rails.logger.info (or debug, or warn) as follows:

Rails.logger.info "Some debugging info I want to see in my development log."

I hope that helps someone.