Class: L2meter::Emitter
- Inherits:
-
Object
- Object
- L2meter::Emitter
- Defined in:
- lib/l2meter/emitter.rb
Constant Summary collapse
- BARE_VALUE_SENTINEL =
Object.new.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #batch ⇒ Object
- #clone ⇒ Object
- #context(*context_data, &block) ⇒ Object
- #count(metric, value = 1) ⇒ Object
-
#initialize(configuration: Configuration.new) ⇒ Emitter
constructor
A new instance of Emitter.
- #log(*args, &block) ⇒ Object
- #measure(metric, value, **args) ⇒ Object
- #sample(metric, value, **args) ⇒ Object
- #silence(&block) ⇒ Object
- #silence! ⇒ Object
- #unique(metric, value) ⇒ Object
- #unsilence! ⇒ Object
- #with_elapsed ⇒ Object
- #with_output(new_output) ⇒ Object
Constructor Details
#initialize(configuration: Configuration.new) ⇒ Emitter
Returns a new instance of Emitter.
9 10 11 |
# File 'lib/l2meter/emitter.rb', line 9 def initialize(configuration: Configuration.new) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/l2meter/emitter.rb', line 5 def configuration @configuration end |
Instance Method Details
#batch ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/l2meter/emitter.rb', line 57 def batch old_state = in_batch? in_batch! yield ensure reset_in_batch(old_state) write end |
#clone ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/l2meter/emitter.rb', line 82 def clone original_contexts = dynamic_contexts original_output = output self.class.new(configuration: configuration).tap do |clone| clone.instance_eval do dynamic_contexts.concat(original_contexts) set_output original_output end end end |
#context(*context_data, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/l2meter/emitter.rb', line 23 def context(*context_data, &block) if block wrap_context(context_data, &block) else contexted(context_data) end end |
#count(metric, value = 1) ⇒ Object
74 75 76 |
# File 'lib/l2meter/emitter.rb', line 74 def count(metric, value = 1) log_with_prefix(:count, metric, value) end |
#log(*args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/l2meter/emitter.rb', line 13 def log(*args, &block) merge!(current_context, *args) if block wrap(&block) else write end end |
#measure(metric, value, **args) ⇒ Object
66 67 68 |
# File 'lib/l2meter/emitter.rb', line 66 def measure(metric, value, **args) log_with_prefix(:measure, metric, value, **args) end |
#sample(metric, value, **args) ⇒ Object
70 71 72 |
# File 'lib/l2meter/emitter.rb', line 70 def sample(metric, value, **args) log_with_prefix(:sample, metric, value, **args) end |
#silence(&block) ⇒ Object
37 38 39 |
# File 'lib/l2meter/emitter.rb', line 37 def silence(&block) with_output(NullOutput.new, &block) end |
#silence! ⇒ Object
41 42 43 |
# File 'lib/l2meter/emitter.rb', line 41 def silence! set_output(NullOutput.new) end |
#unique(metric, value) ⇒ Object
78 79 80 |
# File 'lib/l2meter/emitter.rb', line 78 def unique(metric, value) log_with_prefix(:unique, metric, value) end |
#unsilence! ⇒ Object
45 46 47 |
# File 'lib/l2meter/emitter.rb', line 45 def unsilence! set_output(nil) end |
#with_elapsed ⇒ Object
31 32 33 34 35 |
# File 'lib/l2meter/emitter.rb', line 31 def with_elapsed context elapsed: elapse do yield end end |
#with_output(new_output) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/l2meter/emitter.rb', line 49 def with_output(new_output) old_output = output set_output(new_output) yield ensure set_output(old_output) end |