Class: SyslogGenerator::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/syslog_generator.rb

Overview

Implementation of a log formatter/sender

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Logger

Returns a new instance of Logger.



44
45
46
47
48
49
50
51
52
53
# File 'lib/syslog_generator.rb', line 44

def initialize(options)
  self.options = options
  # TODO: Won't work on systems that don't have `hostname`?
  @formatter = SyslogProtocol::Logger.new(
    `hostname`.strip,
    options[:name],
    options[:facility]
  )
  @socket = initialize_socket(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/syslog_generator.rb', line 10

def options
  @options
end

Instance Method Details

#send(text) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/syslog_generator.rb', line 55

def send(text)
  if options[:test]
    puts(gen_payload(text))
  else
    @socket.send(gen_payload(text), 0, options[:server], options[:port])
  end
end

#startObject



63
64
65
66
67
68
69
# File 'lib/syslog_generator.rb', line 63

def start
  if options[:count] != -1
    options[:count].times { send(gen_words) }
  else
    loop { send(gen_words) }
  end
end