Module: Logglier::Client::InstanceMethods

Included in:
HTTP, Syslog
Defined in:
lib/logglier/client.rb

Instance Method Summary collapse

Instance Method Details

#formatterObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/logglier/client.rb', line 60

def formatter
  proc do |severity, datetime, progname, msg|
    processid=Process.pid
    if @format == :json && msg.is_a?(Hash)
      MultiJson.dump(msg.merge({ :severity => severity,
                                 :datetime => datetime,
                                 :progname => progname,
                                 :pid      => processid }))
    else
      message = "#{datetime} "
      message << massage_message(msg, severity, processid)
    end
  end
end

#masher(hash, prefix = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/logglier/client.rb', line 45

def masher(hash, prefix=nil)
  hash.map do |v|
    if v[1].is_a?(Hash)
      masher(v[1],masherize_key(prefix,v[0]))
    else
      "#{masherize_key(prefix,v[0])}=" << case v[1]
      when Symbol
        v[1].to_s
      else
        v[1].inspect
      end
    end
  end.join(", ")
end

#masherize_key(prefix, key) ⇒ Object



41
42
43
# File 'lib/logglier/client.rb', line 41

def masherize_key(prefix,key)
  [prefix,key.to_s].compact.join('.')
end

#massage_message(incoming_message, severity, processid) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/logglier/client.rb', line 75

def massage_message(incoming_message, severity, processid)
  outgoing_message = ""

  # Append PID and severity to message, unless we're a Syslog
  # client. If we're a Syslog client, that information is already
  # in the Syslog packet.
  unless self.is_a?(Logglier::Client::Syslog)
    outgoing_message << "pid=#{processid}, severity=#{severity}, "
  end

  case incoming_message
  when Hash
    outgoing_message << masher(incoming_message)
  when String
    outgoing_message << incoming_message
  else
    outgoing_message << incoming_message.inspect
  end
  outgoing_message
end

#setup_input_uri(opts) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/logglier/client.rb', line 96

def setup_input_uri(opts)
  @input_uri = opts[:input_url]

  begin
    @input_uri = URI.parse(@input_uri)
  rescue URI::InvalidURIError => e
    raise InputURLRequired.new("Invalid Input URL: #{@input_uri}")
  end
end