spec/betterlog/log_spec.rb in betterlog-0.10.0 vs spec/betterlog/log_spec.rb in betterlog-0.11.0

- old
+ new

@@ -135,26 +135,64 @@ expect(instance).to receive(:emit).with(expected_event) Log.error(exception, foo: 'bar') end end - describe '#measure' do + describe '#metric' do after do Time.dummy = nil end + it 'logs metrics with a specific structure on info log level' do + expected_event = Log::Event.new( + message: 'a metric controller.action=0.123', + name: 'controller.action', + value: 0.123, + type: 'metric', + severity: 'info' + ) + expect(instance).to receive(:emit).with(expected_event) + Log.metric(name: 'controller.action', value: 0.123) + end + + it 'logs metrics on a given log level' do + expected_event = Log::Event.new( + message: 'a metric controller.action=0.123', + name: 'controller.action', + value: 0.123, + type: 'metric', + severity: :info, + ) + expect(instance).to receive(:emit).with(expected_event) + Log.metric(severity: :info, name: 'controller.action', value: 0.123) + end + + it 'logs metrics with additional data' do + expected_event = Log::Event.new( + message: 'a metric controller.action=0.123', + foo: 'bar', + name: 'controller.action', + value: 0.123, + type: 'metric', + severity: 'info' + ) + expect(instance).to receive(:emit).with(expected_event) + Log.metric(name: 'controller.action', value: 0.123, foo: 'bar') + end + it 'can be sent after measuring times' do expected_event = Log::Event.new( message: 'a metric foo=10.0', name: 'foo', value: 10.0, + duration: 10.0, timestamp: "2011-11-11T10:11:21.000Z", type: 'metric', severity: 'info' ) expect(instance).to receive(:emit).with(expected_event) - Log.measure(name: 'foo') do + Log.metric(name: 'foo') do Time.dummy = Time.now + 10 end end class MyEx < StandardError @@ -165,66 +203,29 @@ it 'adds exception information if block raises' do expected_event = Log::Event.new( name: 'foo', value: 3.0, + duration: 3.0, timestamp: "2011-11-11T10:11:14.000Z", message: '"MyEx: we were fucked" while measuring metric foo', error_class: 'MyEx', backtrace: %w[ backtrace ], type: 'metric', severity: 'info' ) expect(instance).to receive(:emit).with(expected_event) raised = false begin - Log.measure(name: 'foo') do + Log.metric(name: 'foo') do Time.dummy = Time.now + 3 raise MyEx, "we were fucked" Time.dummy = Time.now + 7 end rescue MyEx raised = true end expect(raised).to eq true end - end - describe '#metric' do - it 'logs metrics with a specific structure on info log level' do - expected_event = Log::Event.new( - message: 'a metric controller.action=0.123', - name: 'controller.action', - value: 0.123, - type: 'metric', - severity: 'info' - ) - expect(instance).to receive(:emit).with(expected_event) - Log.metric(name: 'controller.action', value: 0.123) - end - - it 'logs metrics on a given log level' do - expected_event = Log::Event.new( - message: 'a metric controller.action=0.123', - name: 'controller.action', - value: 0.123, - type: 'metric', - severity: :info, - ) - expect(instance).to receive(:emit).with(expected_event) - Log.metric(severity: :info, name: 'controller.action', value: 0.123) - end - - it 'logs metrics with additional data' do - expected_event = Log::Event.new( - message: 'a metric controller.action=0.123', - foo: 'bar', - name: 'controller.action', - value: 0.123, - type: 'metric', - severity: 'info' - ) - expect(instance).to receive(:emit).with(expected_event) - Log.metric(name: 'controller.action', value: 0.123, foo: 'bar') - end end end