# What's 'logger', really

**URL:** <https://www.ruby-forum.com/t/whats-logger-really/164283>\
**Category:** Rails\
**Created:** [March 30, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/whats-logger-really/164283 "2009-03-30T22:08:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [March 30, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/whats-logger-really/164283/1 "2009-03-30T22:08:43Z")

</div>

Hi, I don’t understand how we can just call ‘logger’ from any method,  
but when using observers we have to have it attached to some kind of  
object (usually the model of the object being observed). Why is that?  
What is logger exactly?

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [March 30, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/whats-logger-really/164283/2 "2009-03-30T22:32:53Z")

</div>

On Mar 30, 9:08 pm, Steve D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi, I don’t understand how we can just call ‘logger’ from any method,

You can’t call it from any method. ActionController::Base,  
ActiveRecord::Base and a few others have accessors called logger that  
returns a Logger object  
so whenever you’re in an instance method of an ActiveRecord::Base  
subclass you can call it (class methods too - the accessor is defined  
on those classes as well). If the object you’re writing a method for  
doesn’t have a logger method then you can’t call logger, if it does  
you can.

Fred

> but when using observers we have to have it attached to some kind of  
> object (usually the model of the object being observed). Why is that?  
> What is logger exactly?

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [March 31, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/whats-logger-really/164283/3 "2009-03-31T18:46:37Z")

</div>

On Mar 30, 1:32 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You can’t call it from any method. ActionController::Base,  
> ActiveRecord::Base and a few others have accessors called logger that  
> returns a Logger object

Rails also stores a Logger object in RAILS\_DEFAULT\_LOGGER, so you can  
for instance get access to it in testing by including something this  
simple in /test/test\_helper.rb:

def logger  
RAILS\_DEFAULT\_LOGGER  
end

There may be far better ways to find why tests fail, but tossing in  
some

logger.info(“wonky\_var value: #{wonky\_var}”)

calls in unit/functional tests and watching what shows up in /log/  
test.log is pretty useful.

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [April 9, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/whats-logger-really/164283/4 "2009-04-09T19:35:55Z")

</div>

i find I cant send to logger in production mode  
if I am running a script/runner on a model method.

Works in development mode, must be a reason for this although I cant  
figure it

Output just seems to go nowhere

Tonypm
