Skip to content

Commit

Permalink
log: add timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtree9307 committed Mar 12, 2019
1 parent c96891a commit 4ee7873
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions coloredlogcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
]

# Width of various columns; set to -1 to hide
TIME_WIDTH = 18
USER_WIDTH = 3
PROCESS_WIDTH = 8
TAG_WIDTH = 20
PRIORITY_WIDTH = 3

HEADER_SIZE = USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 4
HEADER_SIZE = TIME_WIDTH + USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 4

# unpack the current terminal width/height
data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
Expand Down Expand Up @@ -111,6 +112,7 @@ def allocate_color(tag):
"F": "%s%s%s " % (format(fg=BLACK, bg=RED), "F".center(PRIORITY_WIDTH), format(reset=True)),
}

redetail = re.compile("^([0-9]+-[0-9]+ [0-9\:\.]+)\s+([0-9]+)\s+([0-9]+) ([A-Z]) ([^\:]+)\: (.*)$")
retag = re.compile("^([A-Z])/([^\(]+)\(([^\)]+)\): (.*)$")
retime = re.compile("(?:(\d+)s)?([\d.]+)\dms")
reproc = re.compile(r"^I/ActivityManager.*?: Start proc .*?: pid=(\d+) uid=(\d+)")
Expand All @@ -135,7 +137,7 @@ def millis_color(match):

# if someone is piping in to us, use stdin as input. if not, invoke adb logcat
if os.isatty(sys.stdin.fileno()):
input = os.popen("adb %s logcat -v brief" % adb_args)
input = os.popen("adb %s logcat" % adb_args)
else:
input = sys.stdin

Expand All @@ -153,17 +155,21 @@ def millis_color(match):
if match:
KNOWN_PIDS[int(match.group(1))] = int(match.group(2))

match = retag.match(line)
match = redetail.match(line)
if not match:
print line
continue

priority, tag, process, message = match.groups()
time, ppid, process, priority, tag, message = match.groups()
linebuf = StringIO.StringIO()

tag = tag.strip()
if tag in IGNORED: continue

# time
if TIME_WIDTH > 0:
linebuf.write(time)

# center user info
if USER_WIDTH > 0:
pid = int(process)
Expand Down

0 comments on commit 4ee7873

Please sign in to comment.