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)

  • omit_timezone (Boolean)

    When creating the time-stamp for a log entry, omit the time-zone specifier

  • split_newline (Boolean)

    Split a logging string by newlines, and send each independently to the rtail server NB: You often have to do this, as the rtail server sometimes “squishes” such lines up



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logging/appenders/rtail.rb', line 25

def initialize(name, opts = {})
  @host = opts.fetch(:host, 'localhost')
  @port = opts.fetch(:port, 9999)
  # FIXME: Rtail Server needs to be fixed to allow log-time output in localtime, instead of UTC.
  #        For now, users may need to do this:
  @omit_timezone = opts.fetch(:omit_timezone, false)
  @split_newline = opts.fetch(:split_newline, true)

  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

#hostObject (readonly)

Returns the value of attribute host.



14
15
16
# File 'lib/logging/appenders/rtail.rb', line 14

def host
  @host
end

#omit_timezoneObject (readonly)

Returns the value of attribute omit_timezone.



14
15
16
# File 'lib/logging/appenders/rtail.rb', line 14

def omit_timezone
  @omit_timezone
end

#portObject (readonly)

Returns the value of attribute port.



14
15
16
# File 'lib/logging/appenders/rtail.rb', line 14

def port
  @port
end

#split_newlineObject (readonly)

Returns the value of attribute split_newline.



14
15
16
# File 'lib/logging/appenders/rtail.rb', line 14

def split_newline
  @split_newline
end

Instance Method Details

#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.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/logging/appenders/rtail.rb', line 42

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

  super
  self
end