Rails 3.2.2 log files unordered, requests intertwined

后端 未结 6 1017
礼貌的吻别
礼貌的吻别 2021-02-08 02:02

I recollect getting log files that were nicely ordered, so that you could follow one request, then the next, and so on.

Now, the log files are, as my 4 year old says \"a

6条回答
  •  醉话见心
    2021-02-08 02:25

    Well, for me the TaggedLogging solution is a no go, I can live with some logs getting lost if the server crashes badly, but I want my logs to be perfectly ordered. So, following advice from the issue comments I'm applying this to my app:

    # lib/sequential_logs.rb
    module ActiveSupport
      class BufferedLogger
        def flush
          @log_dest.flush
        end
        def respond_to?(method, include_private = false)
          super
        end
      end
    end
    
    # config/initializers/sequential_logs.rb
    require 'sequential_logs.rb'
    
    Rails.logger.instance_variable_get(:@logger).instance_variable_get(:@log_dest).sync = false
    

    As far as I can say this hasn't affected my app, it is still running and now my logs make sense again.

提交回复
热议问题