Class: LogStash::Outputs::Gelf

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/gelf.rb

Instance Attribute Summary

Attributes inherited from Base

#logger

Instance Method Summary collapse

Constructor Details

#initialize(url, config = {}, &block) ⇒ Gelf

Returns a new instance of Gelf.



14
15
16
17
18
19
20
21
# File 'lib/logstash/outputs/gelf.rb', line 14

def initialize(url, config={}, &block)
  super

  @chunksize = @urlopts["chunksize"].to_i || 1420
  @level = @urlopts["level"] || 1
  @facility = @urlopts["facility"] || 'logstash-gelf'
  
end

Instance Method Details

#receive(event) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/logstash/outputs/gelf.rb', line 33

def receive(event)
  m = Hash.new
  m["short_message"] = (event.fields["message"] or event.message)
  m["full_message"] = (event.message)
  m["host"] = event["@source_host"]
  m["file"] = event["@source_path"]
  m["level"] = 1

  event.fields.each do |name, value|
    next if value == nil or value.empty?
    m["#{name}"] = value
  end
  m["timestamp"] = event.timestamp
  @gelf.notify!(m)
end

#registerObject



24
25
26
27
28
29
30
# File 'lib/logstash/outputs/gelf.rb', line 24

def register
  option_hash = Hash.new
  option_hash["level"] = @level
  option_hash["facility"] = @facility

  @gelf = GELF::Notifier.new(@url.host, (@url.port or 12201), @chunksize, option_hash)
end