Class: Logging::Appenders::Rtail

Inherits:
IO
  • Object
show all
Defined in:
lib/logging/appenders/rtail.rb

Overview

This class provides an Appender that can write to a Rtail service over UDP.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Rtail

Creates a new Rtail Appender that will use the given host and port as the Rtail server destination.

Parameters:

  • name (String)

    Stream ID to differentiate in the Rtail server

  • host (String)

    Host / IP of the Rtail server’s UDP receiver (defaults to “localhost”)

  • port (Integer)

    Port of the Rtail server’s UDP receiver (defaults to 9999)



20
21
22
23
24
25
26
27
28
# File 'lib/logging/appenders/rtail.rb', line 20

def initialize(name, opts = {})
  @host = opts.fetch(:host, 'localhost')
  @port = opts.fetch(:port, 9999)

  fail ArgumentError, 'Empty host and port is not appropriate' unless host && !host.empty? && port

  # Because it's UDP, we want it flushed to the server, immediately:
  super(name, connect(@host, @port), opts.merge(auto_flushing: true))
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



34
35
36
# File 'lib/logging/appenders/rtail.rb', line 34

def port
  @port
end

Instance Method Details

#hostObject



30
31
32
# File 'lib/logging/appenders/rtail.rb', line 30

def host
  @host.dup
end

#reopenObject

Reopen the connection to the underlying logging destination. If the connection is currently closed then it will be opened. If the connection is currently open then it will be closed and immediately opened.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/logging/appenders/rtail.rb', line 39

def reopen
  @mutex.synchronize do
    if defined? @io && @io
      flush
      close rescue nil
    end
    @io = connect(@host, @port)
  end

  super
  self
end