Wolfram Arnold
Wolfram Arnold

Reputation: 7273

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

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?

Upvotes: 1

Views: 513

Answers (1)

Wolfram Arnold
Wolfram Arnold

Reputation: 7273

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.

Upvotes: 1

Related Questions