Class: Fluent::RemoteSyslogTcpOutput

Inherits:
Output
  • Object
show all
Includes:
HandleTagNameMixin, Mixin::ConfigPlaceholders, Mixin::PlainTextFormatter, Mixin::RewriteTagName
Defined in:
lib/fluent/plugin/out_remote_syslog_tcp.rb

Instance Method Summary collapse

Constructor Details

#initializeRemoteSyslogTcpOutput

Returns a new instance of RemoteSyslogTcpOutput.



23
24
25
26
27
28
# File 'lib/fluent/plugin/out_remote_syslog_tcp.rb', line 23

def initialize
  super
  require "remote_syslog_logger_custom"
  require "socket"
  @loggers = {}
end

Instance Method Details

#emit(tag, es, chain) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/out_remote_syslog_tcp.rb', line 35

def emit(tag, es, chain)
  es.each do |time, record|
    new_record = {}
    record.each_pair do |k, v|
      if k == 'msec'
        new_record["timestamp"] = "#{time.to_s}.#{v}".to_f
      elsif v.is_a?(String)
        new_record[k] = v.force_encoding("utf-8")
      else
        new_record[k] = v
      end
    end

    new_record["test_msg"] = time
    tag = rewrite_tag!(tag.dup)
    @loggers[tag] ||= RemoteSyslogLoggerCustom::TcpSender.new(@host,
      @port,
      facility: new_record['facility'] || @facility,
      severity: new_record["severity"] || @severity,
      program: tag,
      local_hostname: Socket.gethostname)
    @loggers[tag].transmit format(tag, time, new_record)
  end
  chain.next
end

#shutdownObject



30
31
32
33
# File 'lib/fluent/plugin/out_remote_syslog_tcp.rb', line 30

def shutdown
  @loggers.values.each(&:close)
  super
end