Class: Timber::Contexts::User

Inherits:
Timber::Context
  • Object
show all
Defined in:
lib/timber/contexts/user.rb

Overview

Note:

This is tracked automatically with the Integrations::Rack::UserContext rack middleware for supported authentication frameworks. See Integrations::Rack::UserContext for more details.

The user context adds data about the currently authenticated user to your logs. By adding this context all of your logs will contain user information. This allows filter and tail logs by specific users.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.



18
19
20
21
22
23
24
# File 'lib/timber/contexts/user.rb', line 18

def initialize(attributes)
  @id = Timber::Util::Object.try(attributes[:id], :to_s)
  @name = attributes[:name]
  @email = attributes[:email]
  @type = attributes[:type]
  @meta = attributes[:meta]
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



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

def meta
  @meta
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

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



27
28
29
# File 'lib/timber/contexts/user.rb', line 27

def as_json(_options = {})
  {id: id, name: name, email: email, type: type, meta: meta}
end