Sha256: 43168817d93d797991c09804f73d678891bef4e20b04e06e95baaad91d763207

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# -*- ruby -*-
# vim: set nosta noet ts=4 sw=4:
# frozen_string_literal: true

require_relative '../../helpers'

require 'loggability/formatter/structured'


describe Loggability::Formatter::Structured do

	before( :each ) do
		ENV['TZ'] = 'UTC'
	end


	it "outputs a stream of JSON objects" do
		expect(
			subject.call('INFO', Time.at(1336286481), nil, "Foom.")
		).to eq(
			%q|{"@version":1,"@timestamp":"2012-05-06T06:41:21.000+00:00"| +
			%q|,"level":"INFO","progname":null,"message":"Foom."}|
		)
	end


	it "includes a time even if called without one" do
		Timecop.freeze( Time.at(1563114765.123) ) do
			expect(
				subject.call('WARN', nil, nil, "Right.")
			).to match( %r(
				\{
					"@version":1,
					"@timestamp":"2019-07-14T14:32:45\.\d{3}\+00:00",
					"level":"WARN",
					"progname":null,
					"message":"Right\."
				\}
			)x )
		end
	end


	it "defaults to DEBUG severity" do
		Timecop.freeze( Time.at(1563114765.123) ) do
			expect(
				subject.call(nil, nil, nil, "Crane.")
			).to match( %r(
				\{
					"@version":1,
					"@timestamp":"2019-07-14T14:32:45\.\d{3}\+00:00",
					"level":"DEBUG",
					"progname":null,
					"message":"Crane\."
				\}
			)x )
		end
	end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
loggability-0.18.2 spec/loggability/formatter/structured_spec.rb
loggability-0.18.1 spec/loggability/formatter/structured_spec.rb
loggability-0.18.0 spec/loggability/formatter/structured_spec.rb
loggability-0.17.0 spec/loggability/formatter/structured_spec.rb
loggability-0.16.0 spec/loggability/formatter/structured_spec.rb
loggability-0.15.1 spec/loggability/formatter/structured_spec.rb