Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To include `adb` and other android tools on your path:

Include these lines in your `.bashrc` or `.zshrc`.


*Note:* `<path to Android SDK>` should be absolute and not relative.

[1]: http://jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/
[2]: http://brew.sh
Expand Down
30 changes: 18 additions & 12 deletions pidcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
parser.add_argument('-i', '--ignore-tag', dest='ignored_tag', action='append', help='Filter output by ignoring specified tag(s)')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__, help='Print the version number and exit')
parser.add_argument('-a', '--all', dest='all', action='store_true', default=False, help='Print all log messages')
parser.add_argument('--timestamp', dest='add_timestamp', action='store_true', help='Prepend each line of output with the current time.')

args = parser.parse_args()
min_level = LOG_LEVELS_MAP[args.min_level.upper()]
Expand Down Expand Up @@ -77,6 +78,8 @@
named_processes = map(lambda package: package if package.find(":") != len(package) - 1 else package[:-1], named_processes)

header_size = args.tag_width + 1 + 3 + 1 # space, level, space
if args.add_timestamp:
header_size += 12 + 1 # time, space

width = -1
try:
Expand Down Expand Up @@ -171,13 +174,13 @@ def allocate_color(tag):
PID_KILL = re.compile(r'^Killing (\d+):([a-zA-Z0-9._:]+)/[^:]+: (.*)$')
PID_LEAVE = re.compile(r'^No longer want ([a-zA-Z0-9._:]+) \(pid (\d+)\): .*$')
PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._:]+) \(pid (\d+)\) has died.?$')
LOG_LINE = re.compile(r'^([A-Z])/(.+?)\( *(\d+)\): (.*?)$')
LOG_LINE = re.compile(r'^[0-9-]+ ([0-9:.]+) ([A-Z])/(.+?)\( *(\d+)\): (.*?)$')
BUG_LINE = re.compile(r'.*nativeGetEnabledTags.*')
BACKTRACE_LINE = re.compile(r'^#(.*?)pc\s(.*?)$')

adb_command = base_adb_command[:]
adb_command.append('logcat')
adb_command.extend(['-v', 'brief'])
adb_command.extend(['-v', 'time'])

# Clear log before starting logcat
if args.clear_logcat:
Expand Down Expand Up @@ -286,7 +289,7 @@ def tag_in_tags_regex(tag, tags):
if log_line is None:
continue

level, tag, owner, message = log_line.groups()
time, level, tag, owner, message = log_line.groups()
tag = tag.strip()
start = parse_start_proc(line)
if start:
Expand Down Expand Up @@ -333,22 +336,25 @@ def tag_in_tags_regex(tag, tags):

linebuf = ''

# right-align tag title and allocate color if needed
if tag != last_tag or args.always_tags:
last_tag = tag
color = allocate_color(tag)
tag = tag[-args.tag_width:].rjust(args.tag_width)
linebuf += colorize(tag, fg=color)
else:
linebuf += ' ' * args.tag_width
linebuf += ' '
if args.tag_width > 0:
# right-align tag title and allocate color if needed
if tag != last_tag or args.always_tags:
last_tag = tag
color = allocate_color(tag)
tag = tag[-args.tag_width:].rjust(args.tag_width)
linebuf += colorize(tag, fg=color)
else:
linebuf += ' ' * args.tag_width
linebuf += ' '

# write out level colored edge
if level in TAGTYPES:
linebuf += TAGTYPES[level]
else:
linebuf += ' ' + level + ' '
linebuf += ' '
if args.add_timestamp:
linebuf = time + ' ' + linebuf

# format tag message using rules
for matcher in RULES:
Expand Down