I have a rails 7 web app, which uses redis
, hiredis
, redis-actionpack
to store session data. We also use devise for auth. Now, I wish to use log tags to include user_id in every line the logger logs. Is there a way to do this without me having to call redis.get
directly and Marshal
ing stuff out?
If we used cookie store - the default thing, shaking the cookie jar would work -
# Prepend all log lines with the following tags. config.log_tags = [:request_id, proc do |req| session_key = Rails.application.config.session_options[:key] session_data = req.cookie_jar.encrypted[session_key] if session_data.present? warden_data = session_data['warden.user.user.key']"user_id: #{warden_data[0][0]}" if warden_data.present? end end]
But I don't want to touch redis directly.
I have tried req.session.to_hash
or req.session[:_csrf_token]
etc to try and force it, but it doesn't stick. I always get an empty {}
back, staring blankly!
How can I use any higher level function to access session data?