Class: Timber::Contexts::Session
- Inherits:
-
Timber::Context
- Object
- Timber::Context
- Timber::Contexts::Session
- Defined in:
- lib/timber/contexts/session.rb
Overview
Note:
This is tracked automatically with the Integrations::Rack::SessionContext rack middleware.
The session context adds the current session ID to your logs. This allows you to tail and filter logs by specific session IDs. Moreover, it gives you a unique identifier to report on user activity by session. This way your logs can tell the story of how many time a user has engaged your site.
Constant Summary collapse
- ID_MAX_BYTES =
256.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ Session
constructor
A new instance of Session.
-
#to_hash ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
Constructor Details
#initialize(attributes) ⇒ Session
Returns a new instance of Session.
20 21 22 23 |
# File 'lib/timber/contexts/session.rb', line 20 def initialize(attributes) normalizer = Util::AttributeNormalizer.new(attributes) @id = normalizer.fetch!(:id, :string, :limit => ID_MAX_BYTES) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
18 19 20 |
# File 'lib/timber/contexts/session.rb', line 18 def id @id end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
32 33 34 |
# File 'lib/timber/contexts/session.rb', line 32 def as_json( = {}) to_hash end |
#to_hash ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
26 27 28 29 30 |
# File 'lib/timber/contexts/session.rb', line 26 def to_hash @to_hash ||= Util::NonNilHashBuilder.build do |h| h.add(:id, id) end end |