11require "net/http"
2- require_relative "../logs_parser/lib/ logs_parser"
2+ require_relative "logs_parser"
33
44class LogFileMonitor
55 def initialize ( log_file_path , initial_position = 0 )
66 @log_file_path = log_file_path
77 @file_position = initial_position
8- @last_size = 0
9- @last_mtime = Time . at ( 0 )
108 @file_handle = nil
9+
10+ if File . exist? ( @log_file_path )
11+ stat = File . stat ( @log_file_path )
12+ @last_size = stat . size
13+ @last_mtime = stat . mtime
14+ else
15+ @last_size = 0
16+ @last_mtime = Time . at ( 0 )
17+ end
1118 end
1219
1320 def file_changed?
@@ -17,10 +24,13 @@ def file_changed?
1724 size_changed = stat . size != @last_size
1825 mtime_changed = stat . mtime != @last_mtime
1926
20- @last_size = stat . size
21- @last_mtime = stat . mtime
22-
23- size_changed || mtime_changed
27+ if size_changed || mtime_changed
28+ @last_size = stat . size
29+ @last_mtime = stat . mtime
30+ true
31+ else
32+ false
33+ end
2434 end
2535
2636 def file_rotated?
@@ -83,7 +93,7 @@ def main
8393 password = ARGV [ 2 ]
8494 initial_position = ARGV [ 3 ] . to_i || 0
8595 host = ARGV [ 4 ] || "fierce-reaches-40697.herokuapp.com"
86- log_file_path = "net_message_debug.log"
96+ log_file_path = ARGV [ 5 ] || "net_message_debug.log"
8797
8898 unless game_name && players_count > 0 && password
8999 puts "Error: game_name, players_count, and password are required"
0 commit comments