diff --git a/lib/splunk_logging.rb b/lib/splunk_logging.rb index 521631512..c32973e82 100644 --- a/lib/splunk_logging.rb +++ b/lib/splunk_logging.rb @@ -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 diff --git a/spec/lib/splunk_logging_spec.rb b/spec/lib/splunk_logging_spec.rb index f2fa5204f..1b7de5a30 100644 --- a/spec/lib/splunk_logging_spec.rb +++ b/spec/lib/splunk_logging_spec.rb @@ -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