Class: WatcherAction::LogAction

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

Overview

Logs the event information to the standard log file

Options

format

A format string that will receive the timestamp, watcher name and event message (in that order) as parameters (default message if not given)

severity

The severity of the log message (default: warn)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ LogAction

Returns a new instance of LogAction.



14
15
16
17
18
19
20
21
# File 'lib/watcher_action/log_action.rb', line 14

def initialize(options)
  @format = options.get_value(:format, "Watcher %s triggered at %s: %s")
  if(severity = options.get_value(:severity))
    @severity = Logger.const_get(severity.upcase)
  else
    @severity = Logger::WARN
  end
end

Instance Method Details

#execute(event) ⇒ Object



23
24
25
# File 'lib/watcher_action/log_action.rb', line 23

def execute(event)
  dog_log.add(@severity, nil, 'LoggerAction') { @format % [event.watcher, event.timestamp, event.message] }
end