Sha256: 3f06a247ce15497d0c99db15de00833240b4053e0dd18627d4afca277777c6b3

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# -*- rspec -*-

require_relative '../helpers'

require 'tempfile'
require 'rspec'

require 'loggability/logger'
require 'loggability/formatter'
require 'loggability/formatter/default'


describe Loggability::Formatter do

	it "formats messages with the pattern it's constructed with" do
		formatter = described_class.new( '[%5$s] %7$s' )
		result = formatter.call( 'INFO', Time.at(1336286481), nil, 'Foom.' )
		expect( result ).to match(/\[INFO\] Foom./i)
	end


	it "formats exceptions into useful messages" do
		formatter = described_class.new( '[%5$s] %7$s' )
		msg = nil

		begin
			raise ArgumentError, "invalid argument"
		rescue => err
			msg = formatter.call( 'INFO', Time.at(1336286481), nil, err )
		end

		expect( msg ).to match(/\[INFO\] ArgumentError: invalid argument/i)
	end


	it "formats regular objects into useful messages" do
		formatter = described_class.new( '[%5$s] %7$s' )
		result = formatter.call( 'INFO', Time.at(1336286481), nil, Object.new )

		expect( result ).to match(/\[INFO\] #<Object:0x[[:xdigit:]]+>/i)
	end


	it "includes the thread ID if logging from a thread other than the main thread" do
		formatter = described_class.new( '%4$d' )
		thr = Thread.new do
			formatter.call( 'INFO', Time.now, nil, 'Foom.' )
		end
		expect( thr.value ).to eq( thr.object_id.to_s )
	end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
loggability-0.14.0 spec/loggability/formatter_spec.rb
loggability-0.13.0 spec/loggability/formatter_spec.rb
loggability-0.12.0 spec/loggability/formatter_spec.rb
loggability-0.12.0.pre20161214121603 spec/loggability/formatter_spec.rb
loggability-0.12.0.pre20161212115530 spec/loggability/formatter_spec.rb