In Android software development, it is important to increase the role of the log, so that we understand the implementation of the program and data. The Eclipse development tool provides a visual tool, but it feels like terminal efficiency is higher, so you write a Python script that filters the log of a program with the package name.
Principle
The corresponding process ID (possibly multiple) is obtained by the package name, and then the log of the corresponding program is obtained using the ADB LOGCAT filtering process ID.
Source
Copy Code code as follows:
#!/usr/bin/env python
#coding: Utf-8
#This the script is aimed to grep logs by application (User should input a packagename and then we are up for the process IDs Then separate logs by Process IDs).
Import OS
Import Sys
Packagename=str (Sys.argv[1])
Command = "adb Shell PS |" grep%s | awk ' {print $} '% (PackageName)
p = os.popen (command)
# #for Some applications,there are multiple processes,so we should get all process ID
PID = P.readline (). Strip ()
filters = PID
while (PID!= ""):
PID = P.readline (). Strip ()
if (PID!= '):
Filters = filters + "|" + PID
#print ' command =%s;filters=%s '% (command, filters)
if (Filters!= '):
cmd = ' adb logcat | grep--color=always-e '%s '% (filters)
Os.system (CMD)
How to use
Copy Code code as follows:
Python logcatpkg.py Com.mx.browser
Latest Code
Copy Code code as follows:
#!/usr/bin/env python
#coding: Utf-8
#This the script is aimed to grep logs by application (User should input a packagename and then we are up for the process IDs Then separate logs by Process IDs).
Import OS
Import Sys
Packagename=str (Sys.argv[1])
Command = "adb Shell PS |" grep%s | awk ' {print $} '% (PackageName)
p = os.popen (command)
# #for Some applications,there are multiple processes,so we should get all process ID
PID = P.readline (). Strip ()
filters = PID
while (PID!= ""):
PID = P.readline (). Strip ()
if (PID!= '):
Filters = filters + "|" + PID
#print ' command =%s;filters=%s '% (command, filters)
if (Filters!= '):
cmd = ' adb logcat | grep--color=always-e '%s '% (filters)
Os.system (CMD)
Insufficient
When the script is executed, the Android program shuts down or restarts, causing the process ID to change and the output log cannot be automatically resumed, and this script can only be executed again.