forked from W3AXL/python-radio-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
55 lines (42 loc) · 2.16 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
45
46
47
48
49
50
51
52
53
54
55
# Colorized logs
from colorama import init, Fore, Back, Style
import time
from datetime import datetime
import inspect
class Logger:
"""-------------------------------------------------------------------------------
Logging Print Functions
-------------------------------------------------------------------------------"""
def __init__(self, verbose=False, debug=False):
# Save verbosity
self.verbose = verbose
self.debug = debug
def initLogs(self):
# Init colorama
init()
def setVerbose(self, verbose):
self.verbose = verbose
def setDebug(self, debug):
self.debug = debug
def logDebug(self, msg):
if self.debug:
callingFunction = inspect.currentframe().f_back.f_code.co_name
timeString = datetime.now().strftime("%m/%d %H:%M:%S.%f")[:-3]
print(Fore.BLUE + Style.DIM + "[{}] ({:^16}) DEBG: {}".format(timeString, callingFunction, str(msg)) + Style.RESET_ALL)
def logVerbose(self, msg):
if self.verbose:
callingFunction = inspect.currentframe().f_back.f_code.co_name
timeString = datetime.now().strftime("%m/%d %H:%M:%S.%f")[:-3]
print(Fore.WHITE + Style.DIM + "[{}] ({:^16}) VERB: {}".format(timeString, callingFunction, str(msg)) + Style.RESET_ALL)
def logInfo(self, msg):
callingFunction = inspect.currentframe().f_back.f_code.co_name
timeString = datetime.now().strftime("%m/%d %H:%M:%S.%f")[:-3]
print(Fore.WHITE + "[{}] ({:^16}) INFO: {}".format(timeString, callingFunction, str(msg)) + Style.RESET_ALL)
def logWarn(self, msg):
callingFunction = inspect.currentframe().f_back.f_code.co_name
timeString = datetime.now().strftime("%m/%d %H:%M:%S.%f")[:-3]
print(Fore.YELLOW + "[{}] ({:^16}) WARN: {}".format(timeString, callingFunction, str(msg)) + Style.RESET_ALL)
def logError(self, msg):
callingFunction = inspect.currentframe().f_back.f_code.co_name
timeString = datetime.now().strftime("%m/%d %H:%M:%S.%f")[:-3]
print(Fore.RED + "[{}] ({:^16}) ERRR: {}".format(timeString, callingFunction, str(msg)) + Style.RESET_ALL)