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 #
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.
Delicious
Digg This Post
Facebook
Reddit This Post
Related posts:
- Receiving Email with Rails This article originally appeared in the first issue of Rails...
- Rails metal call order I was really mystified today trying to figure out how...


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago