Class: Fluent::Plugin::GelfOutput

Inherits:
Output
  • Object
show all
Includes:
GelfPluginUtil
Defined in:
lib/fluent/plugin/out_gelf.rb

Constant Summary

Constants included from GelfPluginUtil

GelfPluginUtil::LEVEL_MAPPING, GelfPluginUtil::SYSLOG_FACILITY

Instance Method Summary collapse

Methods included from GelfPluginUtil

#make_gelfentry, #merge_inner_json

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (ConfigError)


16
17
18
19
# File 'lib/fluent/plugin/out_gelf.rb', line 16

def configure(conf)
  super
  raise ConfigError, "'host' parameter is required" unless conf.key?("host")
end

#format(tag, time, record) ⇒ Object



29
30
31
# File 'lib/fluent/plugin/out_gelf.rb', line 29

def format(tag, time, record)
  make_gelfentry(tag, time, record).to_msgpack
end

#formatted_to_msgpack_binaryObject



51
52
53
# File 'lib/fluent/plugin/out_gelf.rb', line 51

def formatted_to_msgpack_binary
  true
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/fluent/plugin/out_gelf.rb', line 55

def multi_workers_ready?
  true
end

#shutdownObject



25
26
27
# File 'lib/fluent/plugin/out_gelf.rb', line 25

def shutdown
  super
end

#startObject



21
22
23
# File 'lib/fluent/plugin/out_gelf.rb', line 21

def start
  super
end

#write(chunk) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/out_gelf.rb', line 33

def write(chunk) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  records = []
  chunk.msgpack_each do |record|
    records.push JSON.dump(record) + "\0" # Message delimited by null char
  end

  log.debug "establishing connection with GrayLog"
  socket = TCPSocket.new(@host, @port)

  begin
    log.debug "sending #{records.count} records in batch"
    socket.write(records.join)
  ensure
    log.debug "closing connection with GrayLog"
    socket.close
  end
end