Rails 3.1.12中的标记日志记录

时间:2017-07-26 10:57:41

标签: ruby-on-rails ruby-on-rails-3.1 ruby-1.9.3

我想知道如何在3.2以下的Rails版本中实现标记日志记录。我试图使用自定义记录器覆盖logger.rb。

LIB / custom_logger.rb

class CustomLogger < Rails::Rack::Logger

  def initialize(app)
    @app = app
  end

  def call(env)
    before_dispatch(env)
    @app.call(env)
  ensure
    after_dispatch(env)
  end

protected

  def before_dispatch(env)
    request = ActionDispatch::Request.new(env)
    path = request.filtered_path

    info "\n\nStarted #{request.request_method} \"#{path}\" " \
         "for #{request.ip} at #{Time.now.to_default_s}"
  end

  def after_dispatch(env)
    ActiveSupport::LogSubscriber.flush_all!
  end
end
end

并将environment.rb中的行添加为

config.middleware.use CustomLogger

但是,这只允许自定义已启动行。有没有办法自定义所有服务器日志

0 个答案:

没有答案
相关问题