Python Filters individual Android program log script sharing _python

Source: Internet
Author: User
Tags readline python script

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.