Skip to content

Instantly share code, notes, and snippets.

@srt32
Created May 17, 2018 22:23
Show Gist options
  • Save srt32/c61c43fbd5b4ad45227b945ca51b1926 to your computer and use it in GitHub Desktop.
Save srt32/c61c43fbd5b4ad45227b945ca51b1926 to your computer and use it in GitHub Desktop.
logging current user.id in Rails logs
config.log_tags = [
:request_id,
:subdomain,
->(req) {
session_key = (Rails.application.config.session_options || {})[:key]
session_data = req.cookie_jar.encrypted[session_key] || {}
user_id = session_data["user_id"] || "guest"
"user: #{user_id.to_s}"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment