21

Following the advice from my previous question, I placed my background process in an initializer named scheduler.rb. However, I'm having a hard time getting the newly-scheduled processes to log to the Rails logs. Is there a simple way for me to access the same logs from the initializer, preferably by accessing Rails' default logger methods (logger.info, etc)?

Community
  • 1
  • 1
abeger
  • 6,766
  • 7
  • 41
  • 58

3 Answers3

28

Rails 3-
Simply use Rails.logger in your initializer

Rails.logger.info "blabla"

HTH

Hertzel Guinness
  • 5,912
  • 3
  • 38
  • 43
15

RAILS_DEFAULT_LOGGER was deprecated in Rails 3. The following steps work for me in Rails 3.1.

Set your logger in environment.rb before calling initialize! on your application:

Rails.logger = Logger.new(STDOUT)
MyServer::Application.initialize!

Then call the logger in your initializer.

Rails.logger.info "Hello, world!"
Jason
  • 2,025
  • 2
  • 21
  • 13
9
RAILS_DEFAULT_LOGGER.info "abc"
St.Woland
  • 5,357
  • 30
  • 30