-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
44 lines (32 loc) · 1.47 KB
/
logger.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
import colorama
def do_print(*args, flag=None, color=None, sep=' ', start=' ', nident=True):
argv = []
for x in args:
argv.append(str(x))
content = ''.join([flag, start, str(sep.join(argv)).replace('\n', str(
str('\n'+' '*len(flag) if flag else 0) + start) if nident else '\n')]).strip()
print(str('' if not color else color) + content +
colorama.Back.RESET+colorama.Fore.RESET+colorama.Style.RESET_ALL)
def exception(exception):
do_print(exception, flag='EXCEPTION', color=colorama.Fore.RED)
def log(*args, sep=' ', start=' ', nident=True, **kw):
if kw:
do_print(*args, str(kw), flag='LOG',
sep=sep, start=start, nident=nident)
else:
do_print(*args, flag='LOG', sep=sep, start=start, nident=nident, color=colorama.Style.DIM)
def info(*args, sep=' ', start=' ', nident=True, **kw):
if kw:
do_print(*args, str(kw), flag='INFO',
sep=sep, start=start, nident=nident, color=colorama.Fore.GREEN)
else:
do_print(*args, flag='INFO', sep=sep, start=start, nident=nident, color=colorama.Fore.GREEN)
def handled_exception(*args, sep=' ', start=' ', nident=True, **kw):
if kw:
do_print(*args, str(kw), flag='HANEX',
sep=sep, start=start, nident=nident)
else:
do_print(*args, flag='HANEX', sep=sep, start=start, nident=nident)
def hanex(*args,**kw):
'A shorthand for handled_exception'
handled_exception(*args,**kw)