Skip to content

Commit

Permalink
Add timestamps to each message
Browse files Browse the repository at this point in the history
Enabled with the -t flag. Fixes JakeWharton#9
  • Loading branch information
marczych authored and vickychijwani committed Jan 23, 2015
1 parent 00ebabb commit 855a247
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pidcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down Expand Up @@ -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(.*?)$')

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))

0 comments on commit 855a247

Please sign in to comment.