Class: Gallus::Log
- Inherits:
-
Object
- Object
- Gallus::Log
- Defined in:
- lib/gallus/log.rb
Constant Summary collapse
- @@global_context_mutex =
Mutex.new
- @@global_context =
{}
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#serialization ⇒ Object
Returns the value of attribute serialization.
Class Method Summary collapse
- .[](name) ⇒ Object
- .configure(name = '', &block) ⇒ Object
- .current_thread_context {|(Thread.current[:log_context] ||= {})| ... } ⇒ Object
- .define_log_methods!(log_level) ⇒ Object
- .delete(name) ⇒ Object
- .global_context ⇒ Object
- .root ⇒ Object
Instance Method Summary collapse
- #context ⇒ Object
-
#initialize(parent, name) {|_self| ... } ⇒ Log
constructor
A new instance of Log.
Constructor Details
#initialize(parent, name) {|_self| ... } ⇒ Log
Returns a new instance of Log.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gallus/log.rb', line 52 def initialize(parent, name, &block) @parent, @name = parent, name.to_s if parent @output = (@parent.output || []).dup @serialization = @parent.serialization self.level = @parent.level end @output ||= [] @serialization ||= Serialization::Inspect.new yield self if block_given? end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
49 50 51 |
# File 'lib/gallus/log.rb', line 49 def level @level end |
#name ⇒ Object
Returns the value of attribute name.
49 50 51 |
# File 'lib/gallus/log.rb', line 49 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
50 51 52 |
# File 'lib/gallus/log.rb', line 50 def output @output end |
#serialization ⇒ Object
Returns the value of attribute serialization.
49 50 51 |
# File 'lib/gallus/log.rb', line 49 def serialization @serialization end |
Class Method Details
.[](name) ⇒ Object
11 12 13 |
# File 'lib/gallus/log.rb', line 11 def [](name) configure(name) end |
.configure(name = '', &block) ⇒ Object
7 8 9 |
# File 'lib/gallus/log.rb', line 7 def configure(name = '', &block) Repository.get_or_create_logger(name, &block) end |
.current_thread_context {|(Thread.current[:log_context] ||= {})| ... } ⇒ Object
40 41 42 |
# File 'lib/gallus/log.rb', line 40 def current_thread_context yield (Thread.current[:log_context] ||= {}) end |
.define_log_methods!(log_level) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gallus/log.rb', line 19 def define_log_methods!(log_level) Level.each do |level| method_name = level.name.downcase remove_method(method_name) if method_defined?(method_name) if level >= log_level define_method(method_name) do |, payload = {}| log(level, , payload) end else define_method(method_name) do |, payload = {}| # supressed... end end end end |
.delete(name) ⇒ Object
15 16 17 |
# File 'lib/gallus/log.rb', line 15 def delete(name) Repository.delete_with_children(name) end |
.global_context ⇒ Object
36 37 38 |
# File 'lib/gallus/log.rb', line 36 def global_context @@global_context_mutex.synchronize { yield @@global_context } end |
.root ⇒ Object
44 45 46 |
# File 'lib/gallus/log.rb', line 44 def root @@root end |
Instance Method Details
#context ⇒ Object
74 75 76 |
# File 'lib/gallus/log.rb', line 74 def context @context ||= {} end |