I've been working on running a Daemon that has access to the rails environment. From searching around a bit, I've found there are two things I need handle when doing so:
I understand the need to re-initialize a connection to the database, but not the loggers. I saw this code which will aims to make running a Daemon with Rails a bit easier. It creates new BufferedLogger instances for each of: Rails
, ActiveRecord::Base
, ActionController::Base
, ActionMailer::Base
Two things are unclear to me:
logger.info
from code within a controller vs code within a model, is it not using the same rails logger? One thing I've found is that there are quite a few people who have a hard time understanding the Rails loggers. If there are some blog posts that cover this topic already, please let me know!
Well I think 4 loggers were introduced in Rails 3. The idea behind it that each component (ActiveRecord, ActionPack, ActionMailer) are not really dependent on each other and it should be possible to use them standalone. Thus the reason why each of them have their own logger object. I think it's in railties gem where all those 4 loggers are basically set to same instance, so calling logger.info on any of them would mean same result. However in theory you could set ActiveRecord logger to something else for example.
As for why loggers need to be reinitialized I don't know...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.