Last active
February 9, 2017 21:55
-
-
Save mudge/5063930 to your computer and use it in GitHub Desktop.
Unicorn configuration for Rails 3.2 application to log to a different file per worker (to stop logs interleaving with one another).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
logger.level = ActiveSupport::BufferedLogger.const_get(Rails.configuration.log_level.to_s.upcase) | |
logger | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment