I had an issue where I was not sure the ActiveRecord::SessionStore
was actually working (in hindsight: it worked). But to make sure, I needed to know what was stored in the session or retrieved.
All logging for the session-store is silenced, using Base.silence
.
Obviously I was very interested in that logging, and did not find another to unsilence the logging but to add an initializer with the following code.
So in file config/initializers/unsilence_logging.rb
write:
class ActiveRecord::Base
def self.silence
yield self
end
end
This will unsilence the SessionStore
logging. Your logging will look like this:
^[[1m^[[36mAREL (0.0ms)^[[0m ^[[1mUPDATE "sessions" SET "data" = 'BAh7DEkiFnF1aWN<<snipped to protect the inncocent>>iEi9mcC9kYXNoYm9hcmQ= ', "updated_at" = '2012-05-04 11:17:24.704491' WHERE "sessions"."id" = 33635
This at least allows us to verify that the sessions are stored and retrieved correctly. But how can we see what is stored inside the session? To be able to read or inspect what is actually stored in the session, you can use the following line:
session_data = 'BAh7DEkiFnF1aWN<<snipped to protect the inncocent>>iEi9mcC9kYXNoYm9hcmQ= '
Marshal.load(ActiveSupport::Base64.decode64(session_data))
And this will present your session data in a readable format.
This way I learned that a time-drift between our two servers caused a very obscure bug. I hope it can help you too.
Comments
Add comment