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)?
Asked
Active
Viewed 1.1k times
3 Answers
28
Rails 3-
Simply use Rails.logger in your initializer
Rails.logger.info "blabla"
HTH

Hertzel Guinness
- 5,912
- 3
- 38
- 43
-
2Just a quick note about something obvious that I missed for quite a long time. To make this work, you do need to "require 'logger'" – Anne Gunn Jul 22 '14 at 18:27
-
1Works with Rails 4 as well – fkoessler Apr 25 '16 at 12:56
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