Class: Log4r::UDPOutputter

Inherits:
Outputter
  • Object
show all
Defined in:
lib/log4r/outputter/udpoutputter.rb

Instance Attribute Summary collapse

Attributes inherited from Outputter

#formatter, #level, #name

Instance Method Summary collapse

Methods inherited from Outputter

[], []=, each, each_outputter, #flush, #only_at, stderr, stdout

Constructor Details

#initialize(_name, hash = {}) ⇒ UDPOutputter

Returns a new instance of UDPOutputter.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/log4r/outputter/udpoutputter.rb', line 18

def initialize(_name, hash={})
  super(_name, hash)
  @host = hash[:hostname]
  @port = hash[:port]

  begin 
	Logger.log_internal {
	  "UDPOutputter will send to #{@host}:#{@port}"
	}
	@udpsock = UDPSocket.new
	@udpsock.connect( @host, @port )
  rescue Exception => e
	Logger.log_internal(ERROR) {
	  "UDPOutputter failed to create UDP socket: #{e}"
	}
	Logger.log_internal {e}
	self.level = OFF
	raise e
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



15
16
17
# File 'lib/log4r/outputter/udpoutputter.rb', line 15

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



15
16
17
# File 'lib/log4r/outputter/udpoutputter.rb', line 15

def port
  @port
end

#udpsockObject

Returns the value of attribute udpsock.



16
17
18
# File 'lib/log4r/outputter/udpoutputter.rb', line 16

def udpsock
  @udpsock
end