Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Logging Current User
Search
Gaurish Sharma
April 05, 2015
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Logging Current User
Lighting Talk Given at RubyConfIndia 2015
Gaurish Sharma
April 05, 2015
More Decks by Gaurish Sharma
See All by Gaurish Sharma
Issue #11700 - Getting Rails TestSuite to Run on JRuby
gary4gar
0
610
Jaipur.rb User Group Introduction
gary4gar
0
450
Other Decks in Technology
See All in Technology
WasmをRustにする
sansantech
PRO
0
250
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
280
今さら理解するウェブフォントver.2026
takanorip
3
770
Claude Code本は、どのように執筆チームで書かれたか
oikon48
1
380
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.4k
go-sqletch
moznion
0
140
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
430
Getting Started with Google Antigravity
glaforge
0
300
その Valkey 使いこなしていますか?
onk
PRO
5
1.5k
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
390
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
160
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Typedesign – Prime Four
hannesfritz
42
3.2k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
Designing for Timeless Needs
cassininazir
1
530
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
How to build a perfect <img>
jonoalderson
1
6.1k
ラッコキーワード サービス紹介資料
rakko
1
5.3M
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
930
Leo the Paperboy
mayatellez
10
2.4k
Transcript
Logging Current User Gaurish Sharma @gaurish
None
Tagged Logging config/initializers/logging.rb 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 ]
[User:3803] Started GET "/businesses" for 127.0.0.1 at 2015-04-05 12:31:06 +0530
[User:3803] Processing by BusinessesController#index as HTML [User:3803] Completed 200 OK in 548ms (Views: 505.8ms | ActiveRecord: 9.7ms)
Started GET "/businesses" for 127.0.0.1 at 2015-04-04 17:17:41 +0530 User:3803
Processing by BusinessesController#index as HTML Completed 200 OK in 834ms (Views: 527.8ms | ActiveRecord: 262.3ms)
Custom Middleware class CurrentUserLogger < Rails::Rack::Logger end
Custom Middleware class CurrentUserLogger < Rails::Rack::Logger protected def started_request_message(request) end
end
Custom Middleware def started_request_message(request) 'Started %s "%s" for %s at
%s %s' % [ request.request_method, request.filtered_path, request.ip, Time.now.to_default_s, by_current_user(request) ] end
Application.rb config.log_tags = [:subdomain,:uuid] config.middleware.swap(Rails::Rack::Logger,’CurrentUserLogger', config.log_tags)
config.middleware.delete(ActionDispatch::Cooki es) config.middleware.delete(ActionDispatch::Sessi on::CookieStore) config.middleware.insert_before("CurrentUserLo gger”, ActionDispatch::Session::CookieStore) config.middleware.insert_before(ActionDispatch ::Session::CookieStore, ActionDispatch::Cookies)
Easy Way
Hard Way or My Way def by_current_user(request) read_signed_cookie(request) rescue =>
e "" end
Custom Middleware def read_signed_cookie(request) content = URI.unescape(request.cookies[“_app_session”]) key_generator = ActiveSupport::KeyGenerator.new(Rails.config.secret_key_base,
iterations: 1000) key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator) secret = key_generator.generate_key(request.env["action_dispatch.encrypted_cookie_salt"]) sign_secret = key_generator.generate_key(request.env["action_dispatch.encrypted_signed_cookie_salt"]) ActiveSupport::MessageEncryptor.new(secret, sign_secret).decrypt_and_verify(content) rescue ActiveSupport::MessageVerifier::InvalidSignature ‘’ end
Custom Middleware class CurrentUserLogger < Rails::Rack::Logger protected def started_request_message(request) 'Started
%s "%s" for %s at %s %s' % [ request.request_method, request.filtered_path, request.ip, Time.now.to_default_s, by_current_user(request) ] end private def by_current_user(request) ... end def read_signed_cookie(request) ... end end
Earlier
Started GET "/businesses" for 127.0.0.1 at 2015-04-04 17:17:41 +0530 Processing
by BusinessesController#index as HTML Completed 200 OK in 834ms (Views: 527.8ms | ActiveRecord: 262.3ms)
Now
Started GET "/businesses" for 127.0.0.1 at 2015-04-04 17:17:41 +0530 User:3803
Processing by BusinessesController#index as HTML Completed 200 OK in 834ms (Views: 527.8ms | ActiveRecord: 262.3ms)
Thank you!