Class: Timber::Contexts::User
- Inherits:
-
Timber::Context
- Object
- Timber::Context
- Timber::Contexts::User
- Defined in:
- lib/timber/contexts/user.rb
Overview
The user context tracks the currently authenticated user.
You will want to add this context at the time log the user in, typically during the authentication flow.
Note: Timber will attempt to automatically add this if you add a #current_user method to your controllers. Most authentication solutions do this for you automatically.
Example:
user_context = Timber::Contexts::User.new(id: "abc1234", name: "Ben Johnson")
Timber::CurrentContext.with(user_context) do
# Logging will automatically include this context
logger.info("This is a log message")
end
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(attributes) ⇒ User
24 25 26 27 |
# File 'lib/timber/contexts/user.rb', line 24 def initialize(attributes) @id = attributes[:id] @name = attributes[:name] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/timber/contexts/user.rb', line 22 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/timber/contexts/user.rb', line 22 def name @name end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
29 30 31 |
# File 'lib/timber/contexts/user.rb', line 29 def as_json( = {}) {id: id, name: name} end |