31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/fargo/cli/logging.rb', line 31
def log_published_messages
@logging = Hash.new{ |h, k| h[k] = [] }
streamer = proc {
host = "ws://#{client.config.websocket_host}" +
":#{client.config.websocket_port}/"
ws = EventMachine::HttpRequest.new(host).get(:timeout => 0)
ws.disconnect {
Readline.above_prompt{ puts "Stopping logging stream." }
}
ws.callback {
Readline.above_prompt{ puts "Streaming logging messages." }
}
ws.stream { |msg|
to_log = nil
type, message = Marshal.load(Base64.decode64(msg))
@logging[type.to_s].each{ |l|
to_log = l.call message
Readline.above_prompt{ puts to_log } unless to_log.nil?
}
}
}
if EventMachine.reactor_running?
EventMachine.schedule streamer
else
Thread.start{ EventMachine.run streamer }
end
end
|