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)?
If you want to know the current log level, you can call the Rails. logger. level method. This is useful when you want to log under development or staging without flooding your production log with unnecessary information.
By default it puts these log files in the log/ directory of your project. So if you open up that folder you'll see a development.
An initializer is any file of ruby code stored under /config/initializers in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.
Rails 3-
Simply use Rails.logger in your initializer
Rails.logger.info "blabla"
HTH
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!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With