Last active
November 8, 2022 19:18
-
-
Save ilkinulas/2789aabaf89f38df62bd12e2e6990469 to your computer and use it in GitHub Desktop.
Formats unity (adb) logcat logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Usage: | |
# adb logcat -v time | python logcat_unity.py | |
import sys | |
import re | |
IGNORED_LINES=["(Filename:"] | |
LOG_TAG="Unity" | |
REGEX_LINE = "([0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]) ([DIWEF])\/"+LOG_TAG+"\s*\((\s*[0-9]*)\):(.*)" | |
RED="\033[1;31m" | |
YELLOW="\033[1;33m" | |
NO_COLOR="\033[0m" | |
def colorize(color, text): | |
return color + text + NO_COLOR | |
def isDebugOrInfo(log_level): | |
log_level = log_level.rstrip() | |
return log_level=="I" or log_level=="D" | |
def isException(log_message): | |
containsException = (log_message.find("Error") != -1) or (log_message.find("Exception") != -1) | |
return containsException or log_message.strip().startswith("at ") | |
def isIgnored(log_message): | |
for ignored in IGNORED_LINES: | |
if ignored in log_message: | |
return True | |
return False | |
while True: | |
line = sys.stdin.readline().rstrip() | |
match = re.search(REGEX_LINE, line) | |
if not match: | |
continue | |
time = match.group(1) | |
log_level = match.group(2).strip() | |
process_id = match.group(3) | |
log_message = match.group(4) | |
if not log_message: | |
continue | |
if isIgnored(log_message): | |
continue | |
output = time + " " + log_level + " " + log_message | |
if isException(log_message): | |
print colorize(RED, output) | |
elif not isDebugOrInfo(log_level): | |
print colorize(YELLOW, output) | |
else: | |
print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ilkinulas,
First of all, Thank you very much about this script...
I don't know about python. I tried to filter my log but failed . Can you help me?
EX: In my Unity code Debug.Log("---ButtonView---");
I just want to display Log with the message start with char '-'
So, in Line 46 I added:
if not log_message.startswith('-'): continue
But Nothing Displayed, How can I fix that? Any suggestion for me?
Thanks...