Class: Watcher::LogWatcher
Overview
Watches a log file for a given regular expression. This watcher will start a background thread that tails the log and matches against the regexp.
The current implementation is not tested against logs with very high load.
Options
- logfile
-
The log file to watch (required)
- match
-
A regular expression against which the log file will be matched (required)
- *interval_first, interval_max*
-
The start and the max value for waiting on an unchanged log file. They default to 60 (1 minute) and 300 (5 minutes). The log file will be considered stale and reopened after max_value * 3.
Warning
Depending on your Ruby implementation and platform, the background thread may not be taken down if Watchdogger explodes during runtime.
On a clean exit, all threads will be cleanly shut down, but if you kill -9 it, you may want to check for any rogue processes.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(options) ⇒ LogWatcher
constructor
A new instance of LogWatcher.
- #watch_it! ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options) ⇒ LogWatcher
Returns a new instance of LogWatcher.
27 28 29 30 31 32 33 34 35 |
# File 'lib/watcher/log_watcher.rb', line 27 def initialize() @file_name = .get_value(:logfile, false) @match_str = .get_value(:match, false) @interval_first = .get_value(:interval_first, 60).to_i @interval_max = .get_value(:interval_max, 300).to_i watch_log # Start the watcher end |
Instance Method Details
#cleanup ⇒ Object
52 53 54 |
# File 'lib/watcher/log_watcher.rb', line 52 def cleanup @log_watcher.kill if(@log_watcher && !@log_watcher.stop?) end |
#watch_it! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/watcher/log_watcher.rb', line 37 def watch_it! unless(@log_watcher.status) # Restart the watcher if killed for some reason dog_log.warn { "Log watcher on #{@file_name} died? Restarting..." } watch_log end is_triggered = false if(triggered?) is_triggered = "Found #{@match_str} in #{@file_name}" reset_trigger end is_triggered rescue Exception => e "Exception running the log watcher: #{e}" end |