From cf93bfc89b7660aea90424e855753a3d5266cbaf Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 9 Mar 2011 14:06:48 -0800 Subject: [PATCH] improve hash logger a bit --- lib/splunk_logging.rb | 6 +++++- spec/lib/splunk_logging_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 spec/lib/splunk_logging_spec.rb diff --git a/lib/splunk_logging.rb b/lib/splunk_logging.rb index 10008f9f4..91a891040 100644 --- a/lib/splunk_logging.rb +++ b/lib/splunk_logging.rb @@ -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 diff --git a/spec/lib/splunk_logging_spec.rb b/spec/lib/splunk_logging_spec.rb new file mode 100644 index 000000000..f724ab641 --- /dev/null +++ b/spec/lib/splunk_logging_spec.rb @@ -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