improve hash logger a bit

This commit is contained in:
Raphael Sofaer 2011-03-09 14:06:48 -08:00
parent f8c0906db7
commit cf93bfc89b
2 changed files with 26 additions and 1 deletions

View file

@ -11,7 +11,11 @@ module SplunkLogging
if hash.respond_to?(:keys)
string = ''
hash.each_pair do |key, value|
string << "#{key}='#{value}' "
if(value.instance_of?(Symbol)||value.instance_of?(Fixnum))
string << "#{key}=#{value} "
else
string << "#{key}='#{value}' "
end
end
string
else

View file

@ -0,0 +1,21 @@
require 'spec_helper'
describe SplunkLogging do
def add
end
include SplunkLogging
describe '#format_hash' do
it 'does not quote keys' do
format_hash({:key => 'value'}).should =~ /key=/
end
it 'quotes strings' do
format_hash({:key => 'value'}).should =~ /='value'/
end
it 'does not quote symbols' do
format_hash({:key => :value}).should =~ /=value/
end
it 'does not quote numbers' do
format_hash({:key => 500 }).should =~ /=500/
end
end
end