How to split up rails 3.x logger by unicorn workers

Posted . Visible to the public.

config/unicorn/staging.conf

worker_processes 4

after_fork do |server, worker|
  $worker_nr = worker.nr                                                                                                     
end

config/application.rb

module MyApp
  class Application < Rails::Application
    #... lots of config options
    config.logger = ActiveSupport::TaggedLogging.new(Logger.new(Rails.root.join("log", "#{Rails.env}_#{$worker_nr}.log").to_s))
  end
end
Bonyiii
Last edit
Bonyiii
Posted by Bonyiii to Bonyiii's deck (2014-11-12 11:52)