mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
92 lines
2.8 KiB
Ruby
92 lines
2.8 KiB
Ruby
# frozen_string_literal: true
|
|
#
|
|
# Copyright 2017 - 2018 Holger Just
|
|
#
|
|
# This software may be modified and distributed under the terms
|
|
# of the MIT license. See the LICENSE.txt file for details.
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'rackstash/encoder/lograge'
|
|
|
|
RSpec.describe Rackstash::Encoder::Lograge do
|
|
let(:encoder) { described_class.new }
|
|
|
|
describe '#encode' do
|
|
it 'formats the timestamp if present' do
|
|
event = { '@timestamp' => Time.new(2016, 10, 17, 16, 37, 0, '+03:00') }
|
|
expect(encoder.encode(event))
|
|
.to eql 'timestamp=2016-10-17T13:37:00.000000Z'
|
|
end
|
|
|
|
it 'formats multiple values' do
|
|
event = { 'pling' => 'plong', 'toot' => 'chirp' }
|
|
expect(encoder.encode(event))
|
|
.to eql 'pling=plong toot=chirp'
|
|
end
|
|
|
|
it 'formats nested objects' do
|
|
event = { 'pling' => ['plong', nil, { 'toot' => { 'bird' => ['chirp', 'tweet'] } }] }
|
|
expect(encoder.encode(event))
|
|
.to eql 'pling.0=plong pling.2.toot.bird.0=chirp pling.2.toot.bird.1=tweet'
|
|
end
|
|
|
|
it 'formats float values' do
|
|
event = { 'key' => 3.14159, 'rounded' => 4.947 }
|
|
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',
|
|
'error_message' => 'Something',
|
|
'error_trace' => "Foo\nBar\nBaz",
|
|
|
|
'nested' => {
|
|
'error' => 'NestedError',
|
|
'error_message' => 'a message'
|
|
}
|
|
}
|
|
|
|
expect(encoder.encode(event))
|
|
.to eql "error='RuntimeError: Something' nested.error=NestedError nested.error_message=a message"
|
|
end
|
|
|
|
it 'formats an error' do
|
|
event = { 'error' => 'StandardError' }
|
|
expect(encoder.encode(event)).to eql "error='StandardError'"
|
|
end
|
|
|
|
it 'formats an error_message' do
|
|
event = { 'error_message' => 'Something happened' }
|
|
expect(encoder.encode(event)).to eql "error='Something happened'"
|
|
end
|
|
|
|
it 'ignores dots, spaces and equal signs' do
|
|
event = { 'some.key' => 'a.value', 'a=b' => 'c=d', 'a key' => 'some value' }
|
|
expect(encoder.encode(event))
|
|
.to eql 'some.key=a.value a=b=c=d a key=some value'
|
|
end
|
|
|
|
it 'ignores all messages' do
|
|
event = { 'key' => 'value', 'message' => ['foo', 'bar'] }
|
|
expect(encoder.encode(event)).to eql 'key=value'
|
|
end
|
|
end
|
|
end
|