class Fluent::GrayLogOutput

Attributes

endpoint[R]

rubocop:enable Style/NumericLiterals

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_graylog.rb, line 12
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_graylog.rb, line 16
def configure(conf)
  super
  raise ConfigError, "'host' parameter required" unless conf.key?('host')
end
format(_tag, _time, record) click to toggle source
# File lib/fluent/plugin/out_graylog.rb, line 29
def format(_tag, _time, record)
  # Record must already be in GELF
  record.to_msgpack
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_graylog.rb, line 25
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_graylog.rb, line 21
def start
  super
end
write(chunk) click to toggle source

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

# File lib/fluent/plugin/out_graylog.rb, line 35
def write(chunk)
  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