Merge pull request #1326 from micahflee/pretty_verbose

Make verbose output prettier with terminal colors
This commit is contained in:
Saptak Sengupta 2021-04-13 02:45:12 +05:30 committed by GitHub
commit 530f9547f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -43,6 +43,10 @@ class Common:
The Common object is shared amongst all parts of OnionShare. The Common object is shared amongst all parts of OnionShare.
""" """
C_RESET = "\033[0m"
C_LIGHTGRAY = "\033[37m"
C_DARKGRAY = "\033[90m"
def __init__(self, verbose=False): def __init__(self, verbose=False):
self.verbose = verbose self.verbose = verbose
@ -68,10 +72,9 @@ class Common:
""" """
if self.verbose: if self.verbose:
timestamp = time.strftime("%b %d %Y %X") timestamp = time.strftime("%b %d %Y %X")
final_msg = f"{self.C_DARKGRAY}[{timestamp}]{self.C_RESET} {self.C_LIGHTGRAY}{module}.{func}{self.C_RESET}"
final_msg = f"[{timestamp}] {module}.{func}"
if msg: if msg:
final_msg = f"{final_msg}: {msg}" final_msg = f"{final_msg}{self.C_LIGHTGRAY}: {msg}{self.C_RESET}"
print(final_msg) print(final_msg)
def get_resource_path(self, filename): def get_resource_path(self, filename):

View File

@ -241,5 +241,11 @@ class TestLog:
output = buf.getvalue() output = buf.getvalue()
line_one, line_two, _ = output.split("\n") line_one, line_two, _ = output.split("\n")
assert line_one == "[Jun 06 2013 11:05:00] TestModule.dummy_func" assert (
assert line_two == "[Jun 06 2013 11:05:00] TestModule.dummy_func: TEST_MSG" "[Jun 06 2013 11:05:00]" in line_one and "TestModule.dummy_func" in line_one
)
assert (
"[Jun 06 2013 11:05:00]" in line_two
and "TestModule.dummy_func" in line_two
and "TEST_MSG" in line_two
)