Sha256: 166239e2e13d22632644cbbb414dff94e3a8b6193773212bc533597e3dc80a6b

Contents?: true

Size: 641 Bytes

Versions: 7

Compression:

Stored size: 641 Bytes

Contents

# simple UDP logger

require 'logstasher/device'
require 'socket'


module LogStasher
  module Device
    class UDP
      include ::LogStasher::Device

      attr_reader :options, :socket

      def initialize(options = {})
        @options = default_options.merge(stringify_keys(options))
        @socket = UDPSocket.new
      end

      def close
        @socket.close
      end

      def write(log)
        @socket.send(log, 0, options['hostname'], options['port'])
      end

      private

      def default_options
        {
          'hostname' => '127.0.0.1',
          'port'     => 31459,
        }
      end
    end
  end
end



Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
md-logstasher-1.8.0 lib/logstasher/device/udp.rb
md-logstasher-1.7.0 lib/logstasher/device/udp.rb
md-logstasher-1.6.0 lib/logstasher/device/udp.rb
md-logstasher-1.5.0 lib/logstasher/device/udp.rb
md-logstasher-1.4.1 lib/logstasher/device/udp.rb
md-logstasher-1.4.0 lib/logstasher/device/udp.rb
md-logstasher-1.3.0 lib/logstasher/device/udp.rb