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) ⇒ void
Set a context tag.
-
#initialize(parent_context = nil) ⇒ Context
constructor
A new instance of Context.
-
#reset ⇒ void
Clear all the context data.
-
#tag(tags) ⇒ void
Set tags on the context.
Constructor Details
#initialize(parent_context = nil) ⇒ Context
Returns a new instance of Context.
9 10 11 12 |
# File 'lib/lumberjack/context.rb', line 9 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.
28 29 30 |
# File 'lib/lumberjack/context.rb', line 28 def [](key) @tags[key.to_s] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Set a context tag.
37 38 39 |
# File 'lib/lumberjack/context.rb', line 37 def []=(key, value) @tags[key.to_s] = value end |
#reset ⇒ void
This method returns an undefined value.
Clear all the context data.
44 45 46 |
# File 'lib/lumberjack/context.rb', line 44 def reset @tags.clear end |
#tag(tags) ⇒ void
This method returns an undefined value.
Set tags on the context.
18 19 20 21 22 |
# File 'lib/lumberjack/context.rb', line 18 def tag() .each do |key, value| @tags[key.to_s] = value end end |