-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_logging.py
58 lines (49 loc) · 1.28 KB
/
custom_logging.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
import time
from inspect import (
currentframe,
stack
)
def custom_logging_base(text: str, _time: bool, _location: bool, _path: bool):
"""
:param _path:
:param text:
:param _time:
:param _location:
:return:
"""
details = []
if _time:
details.append(str(time.ctime(time.time())))
if _location and _path:
details.append(f"{stack()[1][1]}:{currentframe().f_back.f_lineno}")
elif _location:
double_backslash = "\\"
details.append(f"{stack()[1][1].split('/')[-1].split(double_backslash)[-1]}:{currentframe().f_back.f_lineno}")
if details:
print(f"[{' '.join(details)}] {text}")
def cwarn(text: ..., _time: bool = True, _location: bool = True, _path: bool = False):
"""
custom warning message function
:param _path:
:param _location:
:param _time:
:param text:
:return:
"""
custom_logging_base(str(text), _time, _location, _path)
def clog(text: ..., _time: bool = True):
"""
custom log function
:param _time:
:param text:
:return:
"""
print(f"[{str(time.ctime(time.time()))}] {str(text)}")
def cout(text: ..., _time: bool = True):
"""
custom output function
:param _time:
:param text:
:return:
"""
print(str(text))