Tagged logging in Rails 3.1.12

227 Views Asked by At

I would like to know how the tagged logging can be implemented in Rails versions below 3.2. I have tried to override the logger.rb using a custom logger.

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

And added the line in environment.rb as

config.middleware.use CustomLogger

But however this only allows the Started lines to be customized. Is there any way to customize all server logs

0

There are 0 best solutions below