How to make each unicorn worker of my Rails application log to a different file?

后端 未结 2 1261
情深已故
情深已故 2020-12-24 09:37

How can I make each unicorn worker of my Rails application writting in a different log file ?

The why : problem of mixed log files... In its default configuration, R

2条回答
  •  生来不讨喜
    2020-12-24 10:20

    add this code to after_fork in unicorn.rb:

    #one log per unicorn worker
    if log = Rails.logger.instance_values['log']
      ext = File.extname log.path
      new_path =log.path.gsub %r{(.*)(#{Regexp.escape ext})}, "\\1.#{worker.nr}\\2"
      Rails.logger.instance_eval do
        @log.close
        @log= open_log new_path, 'a+'
      end
    end
    

提交回复
热议问题