Sha256: f5d2b14e7bf358d0320d826bf148ca51e4528efd76b51d9c1c9586f57d21cd19

Contents?: true

Size: 1.01 KB

Versions: 62

Compression:

Stored size: 1.01 KB

Contents

# :include: ../rdoc/outputter
#
# == Other Info
#
# Version:: $Id$
# Author:: Leon Torres <leon@ugcs.caltech.edu>

require "log4r/outputter/outputter"
require 'log4r/staticlogger'
require "socket"

module Log4r

  class UDPOutputter < Outputter
    attr_reader :host, :port
    attr_accessor :udpsock
     
    def initialize(_name, hash={})
      super(_name, hash)
      @host = (hash[:hostname] or hash["hostname"])
      @port = (hash[:port] or 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

    #######
    private
    #######

    def write(data)
      @udpsock.send(data, 0)
    rescue Exception => e
      Logger.log_internal(ERROR) {
	"UDPOutputter failed to send data to #{@host}:#{@port}, #{e}"
      }
    end
    
  end

end

Version data entries

62 entries across 54 versions & 13 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/lib/log4r/outputter/udpoutputter.rb