# Can we get session data in log tags?

**URL:** <https://discuss.rubyonrails.org/t/can-we-get-session-data-in-log-tags/86292>\
**Category:** rubyonrails-talk\
**Tags:** actiondispatch\
**Created:** [July 30, 2024, 10:15am UTC](https://discuss.rubyonrails.org/t/can-we-get-session-data-in-log-tags/86292 "2024-07-30T10:15:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![justLearningRb](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@justLearningRb](https://discuss.rubyonrails.org/u/justLearningRb)\
**Post date:** [July 30, 2024, 10:15am UTC](https://discuss.rubyonrails.org/t/can-we-get-session-data-in-log-tags/86292/1 "2024-07-30T10:15:27Z")

</div>

Hi, 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 working with Marshal?

Earlier when we weren’t using redis store, we used cookie store - the default thing. We had this working, which obviously broke once we moved to redis -

```ruby
   # 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]

```
