Module: Woodchuck::Runner

Extended by:
Fallen, Runner
Included in:
Runner
Defined in:
lib/woodchuck/runner.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject



8
9
10
# File 'lib/woodchuck/runner.rb', line 8

def logger
  @logger ||=  Woodchuck::Logger.new(STDOUT)
end

#logger=(log) ⇒ Object



12
13
14
# File 'lib/woodchuck/runner.rb', line 12

def logger=(log)
  @logger = log
end

#read(args = ARGV) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/woodchuck/runner.rb', line 16

def read(args=ARGV)
  options = {}

  optparse = OptionParser.new do |opts|
    opts.on('-l', '--log-level [LOG_LEVEL]', [:debug, :warn, :info, :error, :fatal], 'set the log level') do |level|
      options[:log_level] = level.to_sym
    end
    opts.on('-o', '--output [OUTPUT]', 'set the output') do |output|
      options[:output] = output.to_sym
    end
    opts.on('-p', '--paths [PATHS]', Array, 'A list of file paths to watch') do |paths|
      options[:paths] = paths
    end
    opts.on('-f', '--format [FORMAT]', [:plain, :json_event], 'Input line format') do |input_format|
      options[:input_format] = input_format
    end
  end
  optparse.parse!(args)
  options
end

#run(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/woodchuck/runner.rb', line 37

def run(options={})
  #puts options.inspect
  agent = Woodchuck::Agent.new(options)
  agent.start(true)
  Signal.trap('INT') do
    @logger.warn :signal => signal
    agent.stop
    exit 0
  end    
end