-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.py
44 lines (33 loc) · 906 Bytes
/
debugger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import inspect
import enum
class LogLevel(enum.Enum):
INFO = 0
WARN = 1
CRIT = 2
EMER = 4
OFF = 5
class db:
PRINT = True
LOGLEVEL = LogLevel.OFF
@staticmethod
def eval(n = None):
if db.PRINT and n != None:
print(f"db [{inspect.stack()[1][2]}] | {db.varName(n)} {type(n)}: {n}")
if db.PRINT and n == None:
print(f"db [{inspect.stack()[2][2]}] | {inspect.stack()[2][1]}")
if callable(n):
return n
@staticmethod
def log(line, level):
if level.value >= db.LOGLEVEL.value:
print(line)
@staticmethod
def loglevel(new_level: LogLevel):
db.LOGLEVEL = new_level
@staticmethod
def varName(var):
return str(inspect.stack()[2][4][0])[12:-2]
@staticmethod
def disable(): db.PRINT = False;
@staticmethod
def enable(): db.PRINT = True;