Skip to content

Commit

Permalink
Add python script to enable colored output of adb logcat.
Browse files Browse the repository at this point in the history
  • Loading branch information
haonan committed Sep 1, 2012
0 parents commit 2987757
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
A simple python script that colorizes the adb logcat output.

Usage
-----

1.) Download and run the colored-adb-logcat.py script:

python colored-adb-logcat.py

2.) Use alias command to create a 'shortcut' to the command:

For example, i use ubuntu, i add follow command in the file: ~/.bashrc
# add colored adb logcat
alias logcat='python /home/haonan/dev/colored-adb-logcat.py'

43 changes: 43 additions & 0 deletions colored-adb-logcat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python

import os, sys, re, StringIO
import fcntl, termios, struct

class COLOR:
WHITE = '\033[37m'
GRAY = '\033[30m'
BLUE = '\033[34m'
GREEN = '\033[92m'
YELLOW = '\033[33m'
RED = '\033[91m'
ENDC = '\033[1;m'


adb_args = ' '.join(sys.argv[1:])

if os.isatty(sys.stdin.fileno()):
input = os.popen("adb logcat %s" % adb_args)
else:
input = sys.stdin

while True:
try:
line = input.readline()
except KeyboardInterrupt:
break

if len(line) == 0: break;
else:
outcolor = COLOR.WHITE
if line[0] == 'E':
outcolor = COLOR.RED
elif line[0] == 'D':
outcolor = COLOR.BLUE
elif line[0] == 'V':
outcolor = COLOR.WHITE
elif line[0] == 'W':
outcolor = COLOR.YELLOW
elif line[0] == 'I':
outcolor = COLOR.GREEN
line = line.strip()
print outcolor + line + COLOR.ENDC

0 comments on commit 2987757

Please sign in to comment.