Class: Process::Daemon::LogFile

Inherits:
File
  • Object
show all
Defined in:
lib/process/daemon/log_file.rb

Overview

This is a special file instance which provides the ability to read a log file from the end backwards.

Instance Method Summary collapse

Instance Method Details

#tail_logObject

Yields the lines of a log file in reverse order, once the yield statement returns true, stops, and returns the lines in order.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/process/daemon/log_file.rb', line 26

def tail_log
  lines = []

  seek_end
  
  reverse_each_line do |line|
    lines << line
    
    break if block_given? and yield line
  end

  return lines.reverse
end