Class: BTC::Diagnostics
- Inherits:
-
Object
- Object
- BTC::Diagnostics
- Defined in:
- lib/btcruby/diagnostics.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#last_info ⇒ Object
Returns the value of attribute last_info.
-
#last_item ⇒ Object
Returns the value of attribute last_item.
-
#last_message ⇒ Object
Returns the value of attribute last_message.
Class Method Summary collapse
-
.current ⇒ Object
Instance unique for this thread.
Instance Method Summary collapse
-
#add_message(message, info: nil) ⇒ Object
Adds a diagnostic message.
-
#record(&block) ⇒ Object
Begins recording of series of messages and returns all recorded events.
-
#trace(stream = $stderr, &block) ⇒ Object
Prints out every message to a stream.
Instance Attribute Details
#last_info ⇒ Object
Returns the value of attribute last_info.
10 11 12 |
# File 'lib/btcruby/diagnostics.rb', line 10 def last_info @last_info end |
#last_item ⇒ Object
Returns the value of attribute last_item.
11 12 13 |
# File 'lib/btcruby/diagnostics.rb', line 11 def last_item @last_item end |
#last_message ⇒ Object
Returns the value of attribute last_message.
9 10 11 |
# File 'lib/btcruby/diagnostics.rb', line 9 def end |
Class Method Details
.current ⇒ Object
Instance unique for this thread.
5 6 7 |
# File 'lib/btcruby/diagnostics.rb', line 5 def self.current Thread.current[:BTCRubyDiagnosticsCurrentInstance] ||= self.new end |
Instance Method Details
#add_message(message, info: nil) ⇒ Object
Adds a diagnostic message. Use it to record warnings and reasons for errors. Do not use when the input is nil - code that have produced that nil could have already recorded a specific message for that.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/btcruby/diagnostics.rb', line 49 def (, info: nil) self. = self.last_info = info self.last_item = Item.new(, info) # add to each recording group recording_groups.each do |group| group << Item.new(, info) end @uniq_trace_streams.each do |stream| stream.puts end return self end |
#record(&block) ⇒ Object
Begins recording of series of messages and returns all recorded events. If there is no record block on any level, messages are not accumulated, but only last_message is updated. Returns a list of all recorded messages.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/btcruby/diagnostics.rb', line 17 def record(&block) recording_groups << Array.new last_group = nil begin yield ensure last_group = recording_groups.pop end last_group end |
#trace(stream = $stderr, &block) ⇒ Object
Prints out every message to a stream. Default stream is $stderr. You can nest these calls with different streams and each of them will receive logged messages.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/btcruby/diagnostics.rb', line 32 def trace(stream = $stderr, &block) @trace_streams << stream # Use uniq list internally so when nested we don't write the same thing twice. @uniq_trace_streams = @trace_streams.uniq begin yield ensure @trace_streams.pop @uniq_trace_streams = @trace_streams.uniq end self end |