Skip to content

Instantly share code, notes, and snippets.

@mudge
mudge / unicorn.conf.rb
Last active February 9, 2017 21:55
Unicorn configuration for Rails 3.2 application to log to a different file per worker (to stop logs interleaving with one another).
after_fork do |server, worker|
# Override the default logger to use a separate log for each Unicorn worker.
# https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/application/bootstrap.rb#L23-L49
Rails.logger = ActiveRecord::Base.logger = ActionController::Base.logger = begin
path = Rails.configuration.paths["log"].first
f = File.open(path.sub(".log", "-#{worker.nr}.log"), "a")
f.binmode
f.sync = true
logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(f))