Last active
September 17, 2018 10:39
-
-
Save x13945/9793cb57f0f61a209cecf0389bb3e925 to your computer and use it in GitHub Desktop.
View android logcat for react-native. Support multi device connected.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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