Class: Steno::Sink::Counter
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #add_record(record) ⇒ Object
-
#counts ⇒ Object
Provide a map of string level -> count.
- #flush ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
9 10 11 12 13 |
# File 'lib/steno/sink/counter.rb', line 9 def initialize # Map of String -> numeric count @counts = {} @mutex = Mutex.new end |
Instance Method Details
#add_record(record) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/steno/sink/counter.rb', line 15 def add_record(record) level = record.log_level.to_s @mutex.synchronize do @counts[level] = 0 unless @counts[level] @counts[level] += 1 end end |
#counts ⇒ Object
Provide a map of string level -> count. This is thread-safe, the return value is a copy.
37 38 39 |
# File 'lib/steno/sink/counter.rb', line 37 def counts @mutex.synchronize { @counts.dup } end |
#flush ⇒ Object
24 |
# File 'lib/steno/sink/counter.rb', line 24 def flush; end |