Class: LogBench::Log::File
- Inherits:
-
Object
- Object
- LogBench::Log::File
- Defined in:
- lib/log_bench/log/file.rb
Instance Attribute Summary collapse
-
#last_position ⇒ Object
readonly
Returns the value of attribute last_position.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #collection ⇒ Object
- #entries ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #lines ⇒ Object
- #mtime ⇒ Object
- #reload! ⇒ Object
- #requests ⇒ Object
- #size ⇒ Object
- #tail(max_lines = 1000) ⇒ Object
- #watch(&block) ⇒ Object
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
8 9 10 11 12 |
# File 'lib/log_bench/log/file.rb', line 8 def initialize(path) self.path = find_log_file(path) self.last_position = 0 validate! end |
Instance Attribute Details
#last_position ⇒ Object
Returns the value of attribute last_position.
6 7 8 |
# File 'lib/log_bench/log/file.rb', line 6 def last_position @last_position end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/log_bench/log/file.rb', line 6 def path @path end |
Instance Method Details
#collection ⇒ Object
22 23 24 |
# File 'lib/log_bench/log/file.rb', line 22 def collection @collection ||= Collection.new(lines) end |
#entries ⇒ Object
18 19 20 |
# File 'lib/log_bench/log/file.rb', line 18 def entries collection.entries end |
#exist? ⇒ Boolean
60 61 62 |
# File 'lib/log_bench/log/file.rb', line 60 def exist? ::File.exist?(path) end |
#lines ⇒ Object
26 27 28 |
# File 'lib/log_bench/log/file.rb', line 26 def lines @lines ||= read_lines end |
#mtime ⇒ Object
64 65 66 |
# File 'lib/log_bench/log/file.rb', line 64 def mtime ::File.mtime(path) end |
#reload! ⇒ Object
30 31 32 33 34 |
# File 'lib/log_bench/log/file.rb', line 30 def reload! self.lines = nil self.collection = nil self.last_position = 0 end |
#requests ⇒ Object
14 15 16 |
# File 'lib/log_bench/log/file.rb', line 14 def requests collection.requests end |
#size ⇒ Object
56 57 58 |
# File 'lib/log_bench/log/file.rb', line 56 def size ::File.size(path) end |
#tail(max_lines = 1000) ⇒ Object
36 37 38 39 40 |
# File 'lib/log_bench/log/file.rb', line 36 def tail(max_lines = 1000) all_lines = read_lines recent_lines = all_lines.last(max_lines) Collection.new(recent_lines) end |
#watch(&block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/log_bench/log/file.rb', line 42 def watch(&block) return enum_for(:watch) unless block_given? loop do new_lines = read_new_lines next if new_lines.empty? new_collection = Collection.new(new_lines) yield new_collection unless new_collection.empty? sleep 0.5 end end |