What's the “official” way to support Unicorn on Heroku and not lose logging?

左心房为你撑大大i 提交于 2019-12-06 13:12:38

问题


We switched to Unicorn, but lost all app logging on Heroku. I googled around a bit and learned Heroku's Ruby buildpack installs a plugin "rails_log_stdout" which doesn't play nice with Unicorn. My guess would be this has something to do with the forking nature of Unicorn, but I didn't confirm that.

Various workarounds like https://gist.github.com/jamiew/2227268 where suggested. These strike me as dis-satisfying because they won't use the log levels defined in the Rails app or any tags, or logger formatting overrides, etc. It seemed a bit brute force to me. What's the "official" way to do this right?


回答1:


This is how I've re-instantiated the logger to avoid losing logging levels or loggin tags. I had to do this separately in each environment file, production.rb, staging.rb (if you have it), etc.

MyApp::Application.configure do

  # ...

  logger = Logger.new(STDOUT)
  logger = ActiveSupport::TaggedLogging.new(logger) if defined?(ActiveSupport::TaggedLogging)
  config.logger = logger
  log_level_env_override = Logger.const_get(ENV['LOG_LEVEL'].try(:upcase)) rescue nil
  config.logger.level = log_level_env_override || Logger.const_get(Rails.configuration.log_level.to_s.upcase)

  # ...

end

I'm not in love with this. I was hoping that there was something more elegant baked into Unicorn.



来源:https://stackoverflow.com/questions/15398045/whats-the-official-way-to-support-unicorn-on-heroku-and-not-lose-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!