-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLog.py
63 lines (50 loc) · 1.79 KB
/
DLog.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import time
import inspect
class DLog:
RED = "\033[31m"
YELLOW = "\033[33m"
RESET = "\033[0m"
YELLOW_BG = "\033[43m" # Fond jaune
GREEN = "\033[32m"
BOLD = "\033[1m"
GRAY = "\033[90m"
def __init__(self):
pass
@staticmethod
def exception(message):
raise(DLog.buildStr(message, DLog.RED))
@staticmethod
def goodbiglog(message):
space = '='*len(message)
print(DLog.buildStr(space, DLog.GREEN))
print(DLog.buildStr(message, DLog.GREEN))
print(DLog.buildStr(space, DLog.GREEN))
@staticmethod
def errorbiglog(message):
space = '!'*len(message)
print(DLog.buildStr(space, DLog.RED))
print(DLog.buildStr(message, DLog.RED))
print(DLog.buildStr(space, DLog.RED))
@staticmethod
def goodlog(message):
print(DLog.buildStr(message, DLog.GREEN))
@staticmethod
def error(message):
print(DLog.buildStr(message, DLog.RED))
@staticmethod
def warning(message):
print(DLog.buildStr(message, DLog.YELLOW))
@staticmethod
def infos(message):
print(DLog.buildStr(message, DLog.RESET))
@staticmethod
def buildStr(message, color):
return DLog.GRAY + str(round(time.time(), 3)) + DLog.RESET + ": " + DLog.get_function_name(inspect.stack()[2]) + color + str(message) + DLog.RESET
@staticmethod
def get_function_name(function):
# ChatGPT code mdr
caller_frame = function
caller_function = caller_frame.function
caller_class = caller_frame.frame.f_locals.get('self',
None).__class__.__name__ if 'self' in caller_frame.frame.f_locals else None
return DLog.BOLD + str(caller_class) + "." + caller_function + "() ==== > " + DLog.RESET