Class: Lumberjack::Context
- Inherits:
-
Object
- Object
- Lumberjack::Context
- Defined in:
- lib/lumberjack/context.rb
Overview
A context is used to store tags that are then added to all log entries within a block.
Instance Attribute Summary collapse
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a context tag.
-
#[]=(key, value) ⇒ Object
Set a context tag.
-
#initialize(parent_context = nil) ⇒ Context
constructor
A new instance of Context.
-
#reset ⇒ Object
Clear all the context data.
-
#tag(tags) ⇒ Object
Set tags on the context.
Constructor Details
#initialize(parent_context = nil) ⇒ Context
Returns a new instance of Context.
8 9 10 11 |
# File 'lib/lumberjack/context.rb', line 8 def initialize(parent_context = nil) @tags = {} @tags.merge!(parent_context.) if parent_context end |
Instance Attribute Details
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/lumberjack/context.rb', line 6 def @tags end |
Instance Method Details
#[](key) ⇒ Object
Get a context tag.
21 22 23 |
# File 'lib/lumberjack/context.rb', line 21 def [](key) @tags[key.to_s] end |
#[]=(key, value) ⇒ Object
Set a context tag.
26 27 28 |
# File 'lib/lumberjack/context.rb', line 26 def []=(key, value) @tags[key.to_s] = value end |
#reset ⇒ Object
Clear all the context data.
31 32 33 |
# File 'lib/lumberjack/context.rb', line 31 def reset @tags.clear end |
#tag(tags) ⇒ Object
Set tags on the context.
14 15 16 17 18 |
# File 'lib/lumberjack/context.rb', line 14 def tag() .each do |key, value| @tags[key.to_s] = value end end |