2018-07-20 15:50:20 -04:00
|
|
|
# coding: utf-8
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::JsonLogger do
|
|
|
|
subject { described_class.new('/dev/null') }
|
|
|
|
|
|
|
|
let(:now) { Time.now }
|
|
|
|
|
|
|
|
describe '#format_message' do
|
2018-12-05 15:54:40 -05:00
|
|
|
before do
|
|
|
|
allow(Gitlab::CorrelationId).to receive(:current_id).and_return('new-correlation-id')
|
|
|
|
end
|
|
|
|
|
2018-07-20 15:50:20 -04:00
|
|
|
it 'formats strings' do
|
|
|
|
output = subject.format_message('INFO', now, 'test', 'Hello world')
|
|
|
|
data = JSON.parse(output)
|
|
|
|
|
|
|
|
expect(data['severity']).to eq('INFO')
|
|
|
|
expect(data['time']).to eq(now.utc.iso8601(3))
|
|
|
|
expect(data['message']).to eq('Hello world')
|
2018-12-06 15:46:31 -05:00
|
|
|
expect(data['correlation_id']).to eq('new-correlation-id')
|
2018-07-20 15:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'formats hashes' do
|
|
|
|
output = subject.format_message('INFO', now, 'test', { hello: 1 })
|
|
|
|
data = JSON.parse(output)
|
|
|
|
|
|
|
|
expect(data['severity']).to eq('INFO')
|
|
|
|
expect(data['time']).to eq(now.utc.iso8601(3))
|
|
|
|
expect(data['hello']).to eq(1)
|
|
|
|
expect(data['message']).to be_nil
|
2018-12-06 15:46:31 -05:00
|
|
|
expect(data['correlation_id']).to eq('new-correlation-id')
|
2018-07-20 15:50:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|