Skip to content

Commit

Permalink
fix bugs:
Browse files Browse the repository at this point in the history
  1. #6
  2. tag is overlapped when it was too long.
  • Loading branch information
bigtree9307 committed Mar 31, 2020
1 parent 7e3f413 commit a51edae
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions coloredlogcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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]) ([^\:]+)\: (.*)$")
redetail = re.compile("^([0-9]+-[0-9]+ [0-9\:\.]+)\s+([0-9]+)\s+([0-9]+) ([\sVDIWEF\s]) ([\S]*)\s*\: (.*)$")
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 Down Expand Up @@ -143,6 +143,9 @@ def millis_color(match):
input = sys.stdin

while True:
line_header_size = HEADER_SIZE
line_tag_width = TAG_WIDTH

try:
line = input.readline()
except KeyboardInterrupt:
Expand All @@ -162,6 +165,9 @@ def millis_color(match):
continue

time, ppid, process, priority, tag, message = match.groups()
if (len(tag) > line_tag_width):
line_tag_width = len(tag)
line_header_size = TIME_WIDTH + PPID_WIDTH + USER_WIDTH + PROCESS_WIDTH + line_tag_width + PRIORITY_WIDTH + 6
linebuf = StringIO.StringIO()

tag = tag.strip()
Expand Down Expand Up @@ -195,14 +201,14 @@ def millis_color(match):
# right-align tag title and allocate color if needed
tag = tag.strip()
if "avc: denied" in message:
tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH)
tag = tag[-line_tag_width:].rjust(line_tag_width)
linebuf.write("%s%s%s " % (format(fg=WHITE, bg=RED, dim=False), tag, format(reset=True)))
elif tag in HIGHLIGHT:
tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH)
tag = tag[-line_tag_width:].rjust(line_tag_width)
linebuf.write("%s%s%s " % (format(fg=BLACK, bg=WHITE, dim=False), tag, format(reset=True)))
else:
color = allocate_color(tag)
tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH)
tag = tag[-line_tag_width:].rjust(line_tag_width)
linebuf.write("%s%s%s " % (format(fg=color, dim=False), tag, format(reset=True)))

# write out tagtype colored edge
Expand All @@ -216,7 +222,7 @@ def millis_color(match):
message = retime.sub(millis_color, message)

# insert line wrapping as needed
message = indent_wrap(message, HEADER_SIZE, WIDTH)
message = indent_wrap(message, line_header_size, WIDTH)

linebuf.write(message)
print linebuf.getvalue()

0 comments on commit a51edae

Please sign in to comment.