Welcome to mirror list, hosted at ThFree Co, Russian Federation.

splunk_logging.rb « lib - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34706b26a2aae97c452b956b18eb80ca82729290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module SplunkLogging
  def self.included(base)
    base.class_eval do
      alias_method_chain :add, :splunk
    end
  end
  def add_with_splunk(arg1, log_hash = nil, arg3 = nil, &block)
    string = format_hash(log_hash).dup
    string << " pid=#{Process.pid} "
    add_without_splunk(arg1, string, arg3, &block)
  end
  def format_hash(hash)
    if hash.respond_to?(:keys)
      string = ''
      hash.each_pair do |key, value|
        if [Symbol, Fixnum, Float, Class].include?(value.class)
           string << "#{key}=#{value} "
        else
           string << "#{key}=\"#{value.to_s.gsub('"', '\"')}\" "
        end
      end
      string
    else
      hash
    end
  end
end