47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
default_debug_name = "*default*"
|
|
debug_activated = set()
|
|
|
|
|
|
def my_debug(*args, check_started=None):
|
|
"""
|
|
Write one line per arg in 'debug.txt'
|
|
:param args:
|
|
:param check_started:
|
|
True : first check if start_debug() was called
|
|
<name> : first check if start_debug(name) was called
|
|
list of <names> : first check if start_debug() is called for all names
|
|
:return:
|
|
"""
|
|
if check_started and default_debug_name not in debug_activated:
|
|
return
|
|
|
|
if isinstance(check_started, str) and check_started not in debug_activated:
|
|
return
|
|
|
|
if isinstance(check_started, list):
|
|
for debug_name in check_started:
|
|
if debug_name not in debug_activated:
|
|
return
|
|
|
|
# with open("debug.txt", "a") as f:
|
|
# for arg in args:
|
|
# if isinstance(arg, list):
|
|
# for item in arg:
|
|
# f.write(f"{item}\n")
|
|
# else:
|
|
# f.write(f"{arg}\n")
|
|
|
|
|
|
def start_debug(debug_name=default_debug_name, msg=None):
|
|
debug_activated.add(debug_name)
|
|
if msg:
|
|
with open("debug.txt", "a") as f:
|
|
f.write(f"{msg}\n")
|
|
|
|
|
|
def stop_debug(debug_name=default_debug_name, msg=None):
|
|
if msg:
|
|
with open("debug.txt", "a") as f:
|
|
f.write(f"{msg}\n")
|
|
debug_activated.remove(debug_name)
|