Class: OohlalogSyslog::FileWatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ FileWatcher



6
7
8
9
10
11
# File 'lib/oohlalog_syslog/file_watcher.rb', line 6

def initialize(filename, options = {})
  @filename = filename
  @category = options["category"] || "NA"
  @options = options
  @logger = Oohlalog::Logger.new(100, 0, options)
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oohlalog_syslog/file_watcher.rb', line 13

def run
  File::Tail::Logfile.open(@filename) do |log|
    log.backward(0)
    log.tail do |line|
      if @options.has_key?("error_pattern") && line.match(@options["error_pattern"])
        @logger.error(line, @category)
      elsif @options.has_key?("fatal_pattern") && line.match(@options["fatal_pattern"])
        @logger.fatal(line, @category)
      elsif @options.has_key?("warn_pattern") && line.match(@options["warn_pattern"])
        @logger.warn(line, @category)
      elsif @options.has_key?("info_pattern") && line.match(@options["info_pattern"])
        @logger.info(line, @category)
      else
        @logger.info(line, @category)
      end
    end
  end
end