6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/log_simulator.rb', line 6
def self.start(filepath,timescale)
begin
socket = TCPSocket.new 'localhost',7658
rescue Exception => _
socket = nil
end
path = File.expand_path(filepath)
puts "Opening log file at path: " + path
if !File.exist? path
puts 'No such file at path '+ path
return
end
time = 0
File.open(path,'r+:utf-8') do |file|
file.each_line do |line|
timestamp_parse(line) do |_time,message|
if time != 0
sleep (_time - time) * timescale
end
if socket != nil
socket.puts message
end
puts '<' + message
time = _time
end
end
end
end
|