diff --git a/README.md b/README.md index 8c3335b..2c7cb4b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To include `adb` and other android tools on your path: Include these lines in your `.bashrc` or `.zshrc`. - +*Note:* `` 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 diff --git a/pidcat.py b/pidcat.py index 570c53b..a90dfe5 100755 --- a/pidcat.py +++ b/pidcat.py @@ -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()] @@ -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: @@ -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: @@ -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: @@ -333,15 +336,16 @@ 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: @@ -349,6 +353,8 @@ def tag_in_tags_regex(tag, tags): else: linebuf += ' ' + level + ' ' linebuf += ' ' + if args.add_timestamp: + linebuf = time + ' ' + linebuf # format tag message using rules for matcher in RULES: