Skip to content

Instantly share code, notes, and snippets.

@ajaykumarns
Created February 20, 2012 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajaykumarns/1867908 to your computer and use it in GitHub Desktop.
Save ajaykumarns/1867908 to your computer and use it in GitHub Desktop.
Script to automate adb logcat
#!/usr/bin/python
import os
import subprocess as sp
import re
from sets import Set
if __name__ == '__main__':
print "Current working directory = %s" % (os.getcwd())
cmd = "find %s -name *.java -exec grep 'Logger\.forK(' '{}' \;" % os.getcwd()
suspend = 'PhoneInterfaceManager,InputDispatcher,NetlinkEvent,UsbObserver,Tethering,Finsky,battery_widget_monitor,KINETO'.split(",")
exclusions = [] #['PackageManager']
debugs = Set()
for line in sp.check_output(cmd, shell=True).split("\n"):
m = re.search('(?<=Logger\.forK\()(\w+)(?=.*\))', line)
if m:
debugs.add(m.group(0))
#oggers += m.group(0) +":D "
cmd = 'find %s -name *.java' % os.getcwd()
for line in sp.check_output(cmd, shell=True).split("\n"):
m = re.search('(\w+).java$', line)
if m:
debugs.add(m.group(1))
for ex in exclusions:
debugs.add(ex)
logs =" ".join([logger + ':D' for logger in debugs])
if len(suspend) > 0:
logs += " " + " ".join([l + ':S' for l in suspend])
cmd = "adb logcat %s *:E" % logs
print "Executing '%s'" % cmd
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment