Class: DLogger::Output::Syslog

Inherits:
Base
  • Object
show all
Defined in:
lib/dlogger/outputs/em/syslog.rb

Overview

This is not strictly a standard syslog output but it is designed to be used with rsyslog as a pass trhough to send data to elasticsearch

Instance Method Summary collapse

Constructor Details

#initialize(host, port, bind_address: '0.0.0.0') ⇒ Syslog

Returns a new instance of Syslog.



13
14
15
16
17
18
# File 'lib/dlogger/outputs/em/syslog.rb', line 13

def initialize(host, port, bind_address: '0.0.0.0')
  @host         = host
  @port         = port
  
  @socket = EM::open_datagram_socket(bind_address, 0)
end

Instance Method Details

#dispatch(msg, metadata) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dlogger/outputs/em/syslog.rb', line 20

def dispatch(msg, )
   = .merge(message: msg)
  
  p = SyslogProtocol::Packet.new
  p.hostname  = "unused"
  p.facility  = "kern"
  p.severity  = "info"
  p.tag       = "app"
  p.content   = MultiJson.encode()
  
  # do not raise an error if eventmachine is not running
  # it might happen when shutting down
  if EM.reactor_running?
    @socket.send_datagram(p.to_s, @host, @port)
  end
end