Class: Timber::Contexts::User
- Inherits:
-
Timber::Context
- Object
- Timber::Context
- Timber::Contexts::User
- Defined in:
- lib/timber/contexts/user.rb
Overview
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.
Constant Summary collapse
- ID_MAX_BYTES =
256.freeze
- NAME_MAX_BYTES =
256.freeze
- EMAIL_MAX_BYTES =
256.freeze
- TYPE_MAX_BYTES =
256.freeze
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ User
constructor
A new instance of User.
-
#to_hash ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
Constructor Details
#initialize(attributes) ⇒ User
Returns a new instance of User.
23 24 25 26 27 28 29 30 |
# File 'lib/timber/contexts/user.rb', line 23 def initialize(attributes) normalizer = Util::AttributeNormalizer.new(attributes) @id = normalizer.fetch(:id, :string, :limit => ID_MAX_BYTES) @name = normalizer.fetch(:name, :string, :limit => NAME_MAX_BYTES) @email = normalizer.fetch(:email, :string, :limit => EMAIL_MAX_BYTES) @type = normalizer.fetch(:type, :string, :limit => TYPE_MAX_BYTES) @meta = normalizer.fetch(:meta, :hash) end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
21 22 23 |
# File 'lib/timber/contexts/user.rb', line 21 def email @email end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/timber/contexts/user.rb', line 21 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
21 22 23 |
# File 'lib/timber/contexts/user.rb', line 21 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/timber/contexts/user.rb', line 21 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/timber/contexts/user.rb', line 21 def type @type end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
43 44 45 |
# File 'lib/timber/contexts/user.rb', line 43 def as_json( = {}) to_hash end |
#to_hash ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
33 34 35 36 37 38 39 40 41 |
# File 'lib/timber/contexts/user.rb', line 33 def to_hash @to_hash ||= Util::NonNilHashBuilder.build do |h| h.add(:id, id) h.add(:name, name) h.add(:email, email) h.add(:type, type) h.add(:meta, ) end end |