Skip to content

Instantly share code, notes, and snippets.

@x13945
Last active September 17, 2018 10:39
Show Gist options
  • Save x13945/9793cb57f0f61a209cecf0389bb3e925 to your computer and use it in GitHub Desktop.
Save x13945/9793cb57f0f61a209cecf0389bb3e925 to your computer and use it in GitHub Desktop.
View android logcat for react-native. Support multi device connected.
#!/usr/bin/env python
# coding:utf-8
# This script is aimed to grep logs for React-Native.
import os
import sys
def getDeviceId():
devices = []
command = "adb devices -l | sed '1d'| awk '{print $1}'"
result = os.popen(command)
deviceId = result.readline().strip()
if deviceId != "":
devices.append(deviceId)
while (deviceId != ""):
deviceId = result.readline().strip()
if deviceId != "":
devices.append(deviceId)
return devices
def printRNLog(device):
# print device, packageName
print "Got device: " + device
command = "adb -s %s logcat *:S ReactNative:V ReactNativeJS:V" % (device)
os.system(command)
devices = getDeviceId()
devicesNum = len(devices)
if devicesNum < 1:
print "Device not found."
elif devicesNum == 1:
device = devices[0]
printRNLog(device)
else:
print "Please chose a dvice, input the index of the device:"
for i in xrange(0, devicesNum):
print str(i) + "\t" + devices[i]
index = raw_input("")
printRNLog(devices[int(index)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment