Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to log user_name in Rails?
- config.log_tags = [:user_name]
- config.log_tags = [ lambda {|req| req.cookie_jar["_session_id"].to_s ]
- config.log_tags = [ lambda {|req| req.cookie_jar["user_name"] || 'Noone' } ]
- config.log_tags = [ lambda { |req| user = req.env['warden'].user; user && user.name || 'Noone'; } ]
- config.log_tags = [ lambda { |req| user = User.find_by_id(req.env['rack.session']['user_id']); user && user.name || 'Noone'; }
- Rails.configuration.log_tags = [
- :uuid, # request UUID
- lambda { |req|
- # Credentials are (currently) in the format of:
- #
- # <session_hash>::<user_id>
- #
- # So we have to split by '::' to obtain the user_id for logging.
- #
- # This will just output "User: nil" if there is no current session.
- "User: #{req.cookies['user_credentials'].to_s.split('::')[1]}"
- }
- ]
- Rails.configuration.log_tags = [
- lambda { |req|
- req.inspect
- }
- ]
- Rails.configuration.log_tags = [
- lambda { |req|
- req.cookies.inspect
- }
- ]
- 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)
- Rails.configuration.log_tags = [
- proc do |req|
- if req.session["warden.user.user.key"].nil?
- "Anonym"
- else
- "user_id:#{req.session["warden.user.user.key"][1][0]}"
- end
- end
- ]
- [Anonym] Served asset ...
- [user_id:1] Served asset ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement