mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
Correctly format date and time objects in Lograge encoder
This commit is contained in:
parent
bb4d8e10bb
commit
fcb1043b6f
@ -126,6 +126,11 @@ module Rackstash
|
||||
value.each_with_index do |array_value, index|
|
||||
add_serialized_field(result, "#{key}.#{index}".freeze, array_value)
|
||||
end
|
||||
when ::Time, ::DateTime
|
||||
value = value.to_time.getutc
|
||||
result[key] = value.iso8601(ISO8601_PRECISION)
|
||||
when ::Date
|
||||
result[key] = value.iso8601
|
||||
when ::Float
|
||||
result[key] = Kernel.format('%.2f'.freeze, value)
|
||||
else
|
||||
|
||||
@ -36,6 +36,21 @@ RSpec.describe Rackstash::Encoder::Lograge do
|
||||
expect(encoder.encode(event)).to eql 'key=3.14 rounded=4.95'
|
||||
end
|
||||
|
||||
it 'formats dates' do
|
||||
event = { 'date' => Date.new(2017, 3, 21) }
|
||||
expect(encoder.encode(event)).to eql 'date=2017-03-21'
|
||||
end
|
||||
|
||||
it 'formats times' do
|
||||
event = { 'time' => Time.new(2016, 10, 17, 16, 37, 0, '+03:00') }
|
||||
expect(encoder.encode(event)).to eql 'time=2016-10-17T13:37:00.000000Z'
|
||||
end
|
||||
|
||||
it 'formats datetimes' do
|
||||
event = { 'time' => DateTime.new(2016, 10, 17, 16, 37, 0, '+03:00') }
|
||||
expect(encoder.encode(event)).to eql 'time=2016-10-17T13:37:00.000000Z'
|
||||
end
|
||||
|
||||
it 'formats complex errors' do
|
||||
event = {
|
||||
'error' => 'RuntimeError',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user