improve hash logger a bit
This commit is contained in:
parent
f8c0906db7
commit
cf93bfc89b
2 changed files with 26 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
21
spec/lib/splunk_logging_spec.rb
Normal file
21
spec/lib/splunk_logging_spec.rb
Normal 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
|
||||
Loading…
Reference in a new issue