问题描述
我们切换到独角兽,但失去了Heroku上的所有应用程序日志记录。我搜索了一下,学习了Heroku的Ruby buildpack安装了一个插件rails_log_stdout,这对Unicorn来说并不好。我的猜测是这与独角兽的分叉性质有关,但我没有证实。像在哪里建议。这些让我感到不满意,因为它们不会使用Rails应用程序中定义的日志级别或任何标记,或者记录器格式覆盖等。这对我来说似乎有点蛮横的力量。什么是正式的方式来做到这一点的权利?
这是我如何重新实例化记录器以避免丢失日志记录级别或登录标签。我必须在每个环境文件 production.rb
, staging.rb
中分别执行此操作(如果有的话) ,等等。
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
我没有爱上这个。我希望有更优雅的东西烘焙到独角兽中。
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?
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.
这篇关于什么是“官方”?在Heroku上支持Unicorn的方式,而不会丢失日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!