Module: SmarterLogging::ControllerHelper

Defined in:
lib/smarter_logging/controller_helper.rb

Constant Summary collapse

KEYS =
[:rqid, :ip, :user_agent]

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/smarter_logging/controller_helper.rb', line 6

def self.included(base)
  base.class_eval do
    before_filter do
      # Get some basic info from the current thread, and add it to the log parameters:
      # The RequestID RQID can be passed-in on subsequent API-calls,
      # so if several APIs call each other, they can be traced with the initial call's RQID
      Thread.current[:rqid] = request.headers['X_RQID'] || SecureRandom.hex(24)
      Thread.current[:ip] = request.remote_ip || request.ip
      Thread.current[:user_agent] = request.user_agent
    end
  end
end