Module: ReactNativeLogCat

Defined in:
lib/react-native-logcat.rb,
lib/react-native-logcat/version.rb

Constant Summary collapse

VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.add_timestamp(str) ⇒ Object



6
7
8
9
# File 'lib/react-native-logcat.rb', line 6

def self.add_timestamp(str)
  timestamp = Time.now.strftime("%H:%M:%S")
  return "[#{timestamp}] #{str}"
end

.startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/react-native-logcat.rb', line 28

def self.start
  cmd='
  adb logcat *:S ReactNative:V ReactNativeJS:V | {
    while IFS= read -r line
    do
      echo "$line"
    done
  }'

  IO.popen(cmd).each do |line|
    puts self.transform_line(line.chomp)
  end
end

.transform_line(str) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/react-native-logcat.rb', line 11

def self.transform_line(str)

  if str[0..1] == "D/"
    return add_timestamp(str.green)
  end

  if str[0..1] == "W/"
    return add_timestamp(str.yellow)
  end

  if str[0..1] == "E/"
    return add_timestamp(str.red)
  end

  return add_timestamp(str)
end