Class: L2met::Syslog

Inherits:
Object
  • Object
show all
Defined in:
lib/l2met/syslog.rb,
lib/l2met/syslog/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Syslog

Returns a new instance of Syslog.



13
14
15
16
# File 'lib/l2met/syslog.rb', line 13

def initialize(options = {})
  @logger   = options[:logger] || default_logger
  @interval = options[:interval] || 60
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



7
8
9
# File 'lib/l2met/syslog.rb', line 7

def interval
  @interval
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/l2met/syslog.rb', line 6

def logger
  @logger
end

Class Method Details

.run(options = {}) ⇒ Object



9
10
11
# File 'lib/l2met/syslog.rb', line 9

def self.run(options = {})
  new(options).run
end

Instance Method Details

#log(params) ⇒ Object



35
36
37
38
39
40
# File 'lib/l2met/syslog.rb', line 35

def log(params)
  if @logger
    message = params.map {|p| p.join('=') }.join(' ')
    @logger.info(message)
  end
end

#log_dataObject



31
32
33
# File 'lib/l2met/syslog.rb', line 31

def log_data
  raise "This method must be implemented"
end

#runObject



18
19
20
21
22
23
24
25
# File 'lib/l2met/syslog.rb', line 18

def run
  @thread = Thread.new do
    loop do
      sleep @interval
      log_data
    end
  end
end

#stopObject



27
28
29
# File 'lib/l2met/syslog.rb', line 27

def stop
  @thread.exit if @thread
end