From 855a247f80ad0998be207871babcb4f00834b737 Mon Sep 17 00:00:00 2001 From: Marc Zych Date: Fri, 6 Sep 2013 14:29:16 -0700 Subject: [PATCH 1/7] Add timestamps to each message Enabled with the -t flag. Fixes #9 --- pidcat.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pidcat.py b/pidcat.py index c275313..eda1099 100755 --- a/pidcat.py +++ b/pidcat.py @@ -41,6 +41,7 @@ parser.add_argument('-c', '--clear', dest='clear_logcat', action='store_true', help='Clear the entire log before running.') parser.add_argument('-t', '--tag', dest='tag', action='append', help='Filter output by specified tag(s)') parser.add_argument('-i', '--ignore-tag', dest='ignored_tag', action='append', help='Filter output by ignoring specified tag(s)') +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()] @@ -145,7 +146,10 @@ 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+)\): (.*?)$') +if args.add_timestamp: + LOG_LINE = re.compile(r'^([0-9-:. ]*) ([A-Z])/(.+?)\( *(\d+)\): (.*?)$') +else: + LOG_LINE = re.compile(r'^([A-Z])/(.+?)\( *(\d+)\): (.*?)$') BUG_LINE = re.compile(r'.*nativeGetEnabledTags.*') BACKTRACE_LINE = re.compile(r'^#(.*?)pc\s(.*?)$') @@ -157,6 +161,8 @@ def allocate_color(tag): if args.use_emulator: adb_command.append('-e') adb_command.append('logcat') +if args.add_timestamp: + adb_command.extend(['-v', 'time']) # Clear log before starting logcat if args.clear_logcat: @@ -240,7 +246,10 @@ def parse_start_proc(line): if log_line is None: continue - level, tag, owner, message = log_line.groups() + if args.add_timestamp: + time, level, tag, owner, message = log_line.groups() + else: + level, tag, owner, message = log_line.groups() start = parse_start_proc(line) if start: line_package, target, line_pid, line_uid, line_gids = start @@ -309,5 +318,8 @@ def parse_start_proc(line): replace = RULES[matcher] message = matcher.sub(replace, message) + if args.add_timestamp: + message = time + " | " + message + linebuf += indent_wrap(message) print(linebuf.encode('utf-8')) From a897e39685ee7c853550eb9e02df47932d9a23e8 Mon Sep 17 00:00:00 2001 From: Vicky Chijwani Date: Fri, 23 Jan 2015 15:09:39 +0530 Subject: [PATCH 2/7] Don't display the date when --timestamp is on. --- pidcat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pidcat.py b/pidcat.py index eda1099..b0c0b0f 100755 --- a/pidcat.py +++ b/pidcat.py @@ -147,7 +147,7 @@ def allocate_color(tag): 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.?$') if args.add_timestamp: - LOG_LINE = re.compile(r'^([0-9-:. ]*) ([A-Z])/(.+?)\( *(\d+)\): (.*?)$') + LOG_LINE = re.compile(r'^[0-9-]+ ([0-9:.]+) ([A-Z])/(.+?)\( *(\d+)\): (.*?)$') else: LOG_LINE = re.compile(r'^([A-Z])/(.+?)\( *(\d+)\): (.*?)$') BUG_LINE = re.compile(r'.*nativeGetEnabledTags.*') From 2e6d2fd20388342a8013364cea5b64c535916f5b Mon Sep 17 00:00:00 2001 From: Vicky Chijwani Date: Sun, 1 Feb 2015 07:02:47 +0530 Subject: [PATCH 3/7] Simplify timestamp capturing code. --- pidcat.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pidcat.py b/pidcat.py index b0c0b0f..8512059 100755 --- a/pidcat.py +++ b/pidcat.py @@ -146,10 +146,7 @@ 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.?$') -if args.add_timestamp: - LOG_LINE = re.compile(r'^[0-9-]+ ([0-9:.]+) ([A-Z])/(.+?)\( *(\d+)\): (.*?)$') -else: - 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(.*?)$') @@ -161,8 +158,7 @@ def allocate_color(tag): if args.use_emulator: adb_command.append('-e') adb_command.append('logcat') -if args.add_timestamp: - adb_command.extend(['-v', 'time']) +adb_command.extend(['-v', 'time']) # Clear log before starting logcat if args.clear_logcat: @@ -246,10 +242,7 @@ def parse_start_proc(line): if log_line is None: continue - if args.add_timestamp: - time, level, tag, owner, message = log_line.groups() - else: - level, tag, owner, message = log_line.groups() + time, level, tag, owner, message = log_line.groups() start = parse_start_proc(line) if start: line_package, target, line_pid, line_uid, line_gids = start From 773a63c86a95b64cc8d3fa4834facaa6d0b24382 Mon Sep 17 00:00:00 2001 From: Vibhav Sinha Date: Fri, 4 Dec 2015 01:12:44 +0530 Subject: [PATCH 4/7] set a defined column for timestamp --- pidcat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pidcat.py b/pidcat.py index fe3e015..b4c8dac 100755 --- a/pidcat.py +++ b/pidcat.py @@ -78,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: @@ -350,14 +352,13 @@ 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: replace = RULES[matcher] message = matcher.sub(replace, message) - if args.add_timestamp: - message = time + " | " + message - linebuf += indent_wrap(message) print(linebuf.encode('utf-8')) From 9e2cca93e63f729097cdbe2fc9b9a7648375b33e Mon Sep 17 00:00:00 2001 From: Andrey Elizarov Date: Fri, 29 Jan 2016 22:15:14 +0300 Subject: [PATCH 5/7] fix bug: '--tag-width 0' does not remove tags --- pidcat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pidcat.py b/pidcat.py index 570c53b..e3d0609 100755 --- a/pidcat.py +++ b/pidcat.py @@ -334,7 +334,7 @@ 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: + if (tag != last_tag or args.always_tags) and args.tag_width > 0: last_tag = tag color = allocate_color(tag) tag = tag[-args.tag_width:].rjust(args.tag_width) From 48aaceea44ada13f41d22de05a13fada8060af97 Mon Sep 17 00:00:00 2001 From: Andrey Elizarov Date: Sat, 30 Jan 2016 03:12:27 +0300 Subject: [PATCH 6/7] fix bug: '--tag-width 0' does not remove tags --- pidcat.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pidcat.py b/pidcat.py index e3d0609..c95c25d 100755 --- a/pidcat.py +++ b/pidcat.py @@ -333,15 +333,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) and args.tag_width > 0: - 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: From 5d2df02af83874058ff93835687291bdea9ff9d9 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Rico Date: Tue, 12 Apr 2016 22:21:18 -0500 Subject: [PATCH 7/7] Help users to avoid errors installing it. (#126) * Help users to avoid errors installing it. Just a description that paths should be absolute and not relative. * Remove link to issue. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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