Clean up the SplunkLogging mixin to make searching in the splunk console a little easier

This commit is contained in:
Raphael Sofaer 2011-06-04 18:35:06 -07:00
parent 158223319e
commit 5314e27e78
2 changed files with 9 additions and 3 deletions

View file

@ -13,10 +13,10 @@ module SplunkLogging
if hash.respond_to?(:keys)
string = ''
hash.each_pair do |key, value|
if(value.instance_of?(Symbol)||value.instance_of?(Fixnum)||value.instance_of?(Float))
if [Symbol, Fixnum, Float, Class].include?(value.class)
string << "#{key}=#{value} "
else
string << "#{key}='#{value}' "
string << "#{key}=\"#{value.to_s.gsub('"', '\"')}\""
end
end
string

View file

@ -9,7 +9,7 @@ describe SplunkLogging do
format_hash({:key => 'value'}).should =~ /key=/
end
it 'quotes strings' do
format_hash({:key => 'value'}).should =~ /='value'/
format_hash({:key => 'value'}).should =~ /="value"/
end
it 'does not quote symbols' do
format_hash({:key => :value}).should =~ /=value/
@ -20,5 +20,11 @@ describe SplunkLogging do
it 'does not quote floats' do
format_hash({:key => 2.324}).should =~ /=2.324/
end
it 'does not quote classes' do
format_hash({:key => Class}).should =~ /=Class/
end
it 'escapes double quotes in strings' do
format_hash({:key => 'whaaa " quotes'}).should =~ /="whaaa \\\" quotes"/
end
end
end