From d53f70917a39e830316f638228497ad1ed896a9a Mon Sep 17 00:00:00 2001 From: Shawn Ma Date: Thu, 13 Jun 2013 14:08:13 -0700 Subject: [PATCH 1/2] support level filtering --- pidcat.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pidcat.py b/pidcat.py index 3603cc4..5d63c59 100755 --- a/pidcat.py +++ b/pidcat.py @@ -29,12 +29,17 @@ import fcntl import termios import struct + +LOG_LEVELS = ['V','D','I','W','E'] +LOG_LEVELS_MAP = dict([(LOG_LEVELS[i], i) for i in range(len(LOG_LEVELS))]) parser = argparse.ArgumentParser(description='Filter logcat by package name') parser.add_argument('package', nargs='+', help='Application package name(s)') -parser.add_argument('--tag-width', metavar='N', dest='tag_width', type=int, default=22, help='Width of log tag') +parser.add_argument('-w', '--tag-width', metavar='N', dest='tag_width', type=int, default=22, help='Width of log tag') +parser.add_argument('-l', '--min-level', dest='min_level', type=str, choices=LOG_LEVELS, default='V', help='Minimal level to be displayed') parser.add_argument('--color-gc', dest='color_gc', action='store_true', help='Color garbage collection') args = parser.parse_args() +min_level=LOG_LEVELS_MAP[args.min_level] header_size = args.tag_width + 1 + 3 + 1 # space, level, space @@ -189,6 +194,8 @@ while True: if owner not in pids: continue + if LOG_LEVELS_MAP[level] < min_level: + continue linebuf = '' From 4095d3aae7545a2e97ec5e095cf8f14db7c826aa Mon Sep 17 00:00:00 2001 From: Shawn Ma Date: Sat, 15 Jun 2013 11:00:47 -0700 Subject: [PATCH 2/2] text change: "Minimum level" --- pidcat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pidcat.py b/pidcat.py index 5d63c59..8455d76 100755 --- a/pidcat.py +++ b/pidcat.py @@ -35,7 +35,7 @@ LOG_LEVELS_MAP = dict([(LOG_LEVELS[i], i) for i in range(len(LOG_LEVELS))]) parser = argparse.ArgumentParser(description='Filter logcat by package name') parser.add_argument('package', nargs='+', help='Application package name(s)') parser.add_argument('-w', '--tag-width', metavar='N', dest='tag_width', type=int, default=22, help='Width of log tag') -parser.add_argument('-l', '--min-level', dest='min_level', type=str, choices=LOG_LEVELS, default='V', help='Minimal level to be displayed') +parser.add_argument('-l', '--min-level', dest='min_level', type=str, choices=LOG_LEVELS, default='V', help='Minimum level to be displayed') parser.add_argument('--color-gc', dest='color_gc', action='store_true', help='Color garbage collection') args = parser.parse_args()