Forum: Ruby on Rails Access rails logger from plain class

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gary B. (Guest)
on 2005-12-29 22:58
How can I "get" the rails logger from a plain class, that is a class
that does not inherit from a rails class?

I have tried using RAILS_DEFAULT_LOGGER (see below) but it's nil

class MyClass

  logger = RAILS_DEFAULT_LOGGER

  def myMethod
    logger.debug("stuff...")
  end

end
Francois B. (Guest)
on 2005-12-29 23:04
(Received via mailing list)
Hi !

2005/12/29, Gary B. <removed_email_address@domain.invalid>:
> class MyClass
>
>   logger = RAILS_DEFAULT_LOGGER
>
>   def myMethod
>     logger.debug("stuff...")
>   end
>
> end

In #myMethod, Ruby will resolve logger as a local variable, which is
nil.  What you should do instead is:

class MyClass
  def logger
    RAILS_DEFAULT_LOGGER
  end

  def myMethod
    logger.debug "stuff"
  end
end

Hope that helps !
Gary B. (Guest)
on 2005-12-29 23:19
Thanks working now.

Another logger question
"HowtoAccessTheLogFile" on the RoR wiki shows RAILS_DEFAULT_LOGGER setup
in environment.rb but I can't see it in my environment.rb. Has this
changed? I have rails v1.0
This topic is locked and can not be replied to.