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 ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
10 11 12 13 14 |
# File 'lib/steno/sink/counter.rb', line 10 def initialize # Map of String -> numeric count @counts = {} @mutex = Mutex.new end |
Instance Method Details
#add_record(record) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/steno/sink/counter.rb', line 16 def add_record(record) level = record.log_level.to_s @mutex.synchronize do unless @counts[level] @counts[level] = 0 end @counts[level] += 1 end end |
#counts ⇒ Object
Provide a map of string level -> count. This is thread-safe, the return value is a copy.
41 42 43 |
# File 'lib/steno/sink/counter.rb', line 41 def counts @mutex.synchronize { @counts.dup } end |
#flush ⇒ Object
27 28 |
# File 'lib/steno/sink/counter.rb', line 27 def flush end |