Skip to content

Instantly share code, notes, and snippets.

@timonv
Last active December 17, 2015 14:49
Show Gist options
  • Save timonv/5626953 to your computer and use it in GitHub Desktop.
Save timonv/5626953 to your computer and use it in GitHub Desktop.
Show UserID in log files with UUID
# Hack around the middleware stack a bit to get warden session correctly in
config.middleware.delete(ActionDispatch::Cookies)
config.middleware.delete(ActionDispatch::Session::CookieStore)
config.middleware.insert_before(Rails::Rack::Logger, ActionDispatch::Session::CookieStore)
config.middleware.insert_before(ActionDispatch::Session::CookieStore, ActionDispatch::Cookies)
# Rotate two files, max 5 mb each
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(config.paths['log'].first, 2, 5 * 1024 * 1024))
config.log_tags = [
:uuid,
-> request {
key = request.session["warden.user.user.key"] #Second user is the name of the authenticating object
if key
"ClientAccount##{key[0][0]}"
else
"Anonymous"
end
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment