1

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?

Wolfram Arnold
  • 7,159
  • 5
  • 44
  • 64
  • 1
    I followed https://blog.heroku.com/archives/2013/2/27/unicorn_rails last night and I can see logs coming through just fine. – John Beynon Mar 14 '13 at 08:34
  • what version of rails and unicorn? I'm switched an app to Unicorn and still see my logs – catsby Mar 14 '13 at 12:48
  • We're using Rails 3.2.11 and Unicorn 4.6.2. I had to re-instantiate the logger inside the production.rb file. Then I got it to work. Thanks for the link to the Heroku post. That was writter a few days after we did this, but we already had the basic structure and it doesn't say anything about logging. – Wolfram Arnold Mar 14 '13 at 19:36
  • @WolframArnold could you explain how you re-instantiated the logger in `production.rb`? – Christian Fazzini Jun 25 '13 at 07:36
  • I'm going to add an answer for this. – Wolfram Arnold Jun 26 '13 at 00:52

1 Answers1

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.

Wolfram Arnold
  • 7,159
  • 5
  • 44
  • 64