Class: RokuBuilder::Monitor
- Extended by:
- Plugin
- Defined in:
- lib/roku_builder/plugins/monitor.rb
Overview
Monitor development Logs
Class Method Summary collapse
Instance Method Summary collapse
-
#init ⇒ Object
Initialize port config.
-
#monitor(options:) ⇒ Object
Monitor a development log on the Roku device.
Methods included from Plugin
commands, dependencies, parse_options, validate
Methods inherited from Util
Constructor Details
This class inherits a constructor from RokuBuilder::Util
Class Method Details
.commands ⇒ Object
9 10 11 |
# File 'lib/roku_builder/plugins/monitor.rb', line 9 def self.commands { monitor: {device: true}} end |
.parse_options(parser:, options:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/roku_builder/plugins/monitor.rb', line 13 def self.(parser:, options:) parser.separator "Commands:" parser.on("-m", "--monitor [TYPE]", "Run telnet to monitor roku log") do |m| [:monitor] = m || "main" end parser.separator "Options:" parser.on("-R", "--regexp REGEXP", "A regular expression used to filter monitor logs") do |r| [:regexp] = r end end |
Instance Method Details
#init ⇒ Object
Initialize port config
25 26 27 28 29 30 31 |
# File 'lib/roku_builder/plugins/monitor.rb', line 25 def init() @ports = { main: 8085, profiler: 8080, } @show_prompt = false end |
#monitor(options:) ⇒ Object
Monitor a development log on the Roku device
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/roku_builder/plugins/monitor.rb', line 34 def monitor(options:) get_device(no_lock: true) do |device| type = [:monitor].to_sym telnet_config = { 'Host' => device.ip, 'Port' => @ports[type] } waitfor_config = { 'Match' => /./, 'Timeout' => false } thread = Thread.new(telnet_config, waitfor_config) {|telnet,waitfor| @logger.info "Monitoring #{type} console(#{telnet['Port']}) on #{telnet['Host'] }" connection = Net::Telnet.new(telnet) Thread.current[:connection] = connection all_text = "" while true connection.waitfor(waitfor) do |txt| all_text = manage_text(all_text: all_text, txt: txt, regexp: [:regexp]) end end } thread.abort_on_exception = true init_readline() run_prompt(thread: thread) end end |