Class: Timber::Contexts::Session

Inherits:
Timber::Context
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Session

Returns a new instance of Session.



18
19
20
# File 'lib/timber/contexts/session.rb', line 18

def initialize(attributes)
  @id = Timber::Util::Object.try(attributes[:id], :to_s) || raise(ArgumentError.new(":id is required"))
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/timber/contexts/session.rb', line 16

def id
  @id
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

Builds a hash representation containing simple objects, suitable for serialization (JSON).



23
24
25
# File 'lib/timber/contexts/session.rb', line 23

def as_json(_options = {})
  {id: id}
end