when you work with rails 3.2, you can use log tags:
Updating Rails :: Rack :: Logger middleware to apply any tags set to config.log_tags for the new ActiveSupport :: TaggedLogging Rails.logger. This makes it easy to mark log lines with debugging information similar to the subdomain and request identifier - both very useful in debugging DHH multi-user production applications.
with luck, adding this to your environment may work:
config.log_tags = [:uuid, :remote_ip, :session_id]
UPDATE
for the loser, the solution is taken from @shigeya's answer.
Unfortunately, rails does NOT provide a way to access your sessionid in a reasonable way. you always have to rely on what the rack does inside it ... accessing the cookie_jar with your cookie key is the โrecommendedโ way to do this.
this is what i use for my application:
config.log_tags = [ :host, :remote_ip, lambda { |request| "#{request.uuid}"[0..15] }, lambda { |request| "#{request.cookie_jar["_session_id"]}"[0..15] }, ]
The output is as follows:
[hamburg.onruby.dev] [127.0.0.1] [27666d0897c88b32] [BAh7B0kiD3Nlc3Np] Completed 200 OK in 298ms (Views: 286.2ms | ActiveRecord: 9.2ms)
source share