Clean up the SplunkLogging mixin to make searching in the splunk console a little easier
This commit is contained in:
parent
158223319e
commit
5314e27e78
2 changed files with 9 additions and 3 deletions
|
|
@ -13,10 +13,10 @@ module SplunkLogging
|
||||||
if hash.respond_to?(:keys)
|
if hash.respond_to?(:keys)
|
||||||
string = ''
|
string = ''
|
||||||
hash.each_pair do |key, value|
|
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} "
|
string << "#{key}=#{value} "
|
||||||
else
|
else
|
||||||
string << "#{key}='#{value}' "
|
string << "#{key}=\"#{value.to_s.gsub('"', '\"')}\""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
string
|
string
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ describe SplunkLogging do
|
||||||
format_hash({:key => 'value'}).should =~ /key=/
|
format_hash({:key => 'value'}).should =~ /key=/
|
||||||
end
|
end
|
||||||
it 'quotes strings' do
|
it 'quotes strings' do
|
||||||
format_hash({:key => 'value'}).should =~ /='value'/
|
format_hash({:key => 'value'}).should =~ /="value"/
|
||||||
end
|
end
|
||||||
it 'does not quote symbols' do
|
it 'does not quote symbols' do
|
||||||
format_hash({:key => :value}).should =~ /=value/
|
format_hash({:key => :value}).should =~ /=value/
|
||||||
|
|
@ -20,5 +20,11 @@ describe SplunkLogging do
|
||||||
it 'does not quote floats' do
|
it 'does not quote floats' do
|
||||||
format_hash({:key => 2.324}).should =~ /=2.324/
|
format_hash({:key => 2.324}).should =~ /=2.324/
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue