Class: LogMuncher

Inherits:
Object
  • Object
show all
Includes:
Styles
Defined in:
lib/replicant/log_muncher.rb

Constant Summary collapse

LOGFILE =
"/tmp/replicant_device"
TIMESTAMP_PATTERN =
/^\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}/
PROCESS_PATTERN =
/(\w){1}\/(.*)\(\s*([0-9]+)\):\s/

Constants included from Styles

Styles::CONSOLE_WIDTH, Styles::REPL_OUT, Styles::STYLES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Styles

#create_style, #end_style, #styled_text

Constructor Details

#initialize(repl) ⇒ LogMuncher

Returns a new instance of LogMuncher.



11
12
13
14
# File 'lib/replicant/log_muncher.rb', line 11

def initialize(repl)
  @repl = repl
  @current_pid = nil
end

Instance Attribute Details

#current_pidObject

Returns the value of attribute current_pid.



9
10
11
# File 'lib/replicant/log_muncher.rb', line 9

def current_pid
  @current_pid
end

Instance Method Details

#munch_logs {|o| ... } ⇒ Object

Parses the device logs and reformats / recolors them

Yields:

  • (o)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/replicant/log_muncher.rb', line 17

def munch_logs
  logcat = "logcat -v time"

  i = IO.popen(AdbCommand.new(@repl, logcat).command)
  o = File.open(LOGFILE, 'wt')

  yield o if block_given?

  Thread.new do
    begin
      i.each_line do |line|
        log_line(o, line)
      end
    rescue Exception => e
      puts e.inspect
      puts e.backtrace.join("\n")
      raise e
    end
  end
end