35 {
'level': 50,
'name':
'critical',
'color':
'\x1b[101m'},
36 {
'level': 40,
'name':
'error',
'color':
'\x1b[91m'},
37 {
'level': 35,
'name':
'success',
'color':
'\x1b[92m'},
38 {
'level': 30,
'name':
'warning',
'color':
'\x1b[93m'},
39 {
'level': 25,
'name':
'notice',
'color':
'\x1b[95m'},
40 {
'level': 20,
'name':
'info',
'color':
'\x1b[37m'},
41 {
'level': 15,
'name':
'verbose',
'color':
'\x1b[94m'},
42 {
'level': 10,
'name':
'debug',
'color':
'\x1b[32m'},
43 {
'level': 5,
'name':
'spam',
'color':
'\x1b[90m'}
52LEVEL_COLUMN_WIDTH: int = 0
57_is_initialized: bool =
False
62UnexpExcInfo = collections.namedtuple(
64 [
'typ',
'val',
'fil',
'lin',
'qnm',
'tbk']
74 global LEVEL_COLUMN_WIDTH
76 for item
in LOG_LEVELS:
77 lln = len(item[
'name'])
78 if LEVEL_COLUMN_WIDTH < lln:
79 LEVEL_COLUMN_WIDTH = lln
81 if 'LOG_LEVEL' in os.environ:
82 LOG_LEVEL = int(os.environ[
'LOG_LEVEL'])
84 global _is_initialized
85 _is_initialized =
True
91 return _is_initialized
100 maj, mno, _ = platform.python_version_tuple()
103 ty, va, tb = exc_info
104 if (maj > 3)
or ((maj == 3)
and (mno >= 11)):
105 qnm = tb.tb_frame.f_code.co_qualname
107 qnm = tb.tb_frame.f_code.co_name
111 tb.tb_frame.f_code.co_filename,
116 tbs =
''.join(traceback.extract_tb(i.tbk).format())
118 'Unexpected {}, "{}"\n'.format(i.typ, i.val) +
119 '\x20\x20File: "{}:{}"\n'.format(i.fil, i.lin) +
120 '\x20\x20Pos.: {}, line {}\n'.format(i.qnm, i.lin) +
121 'Traceback (most recent call last):\n' +
130 if isinstance(msg, str):
132 elif isinstance(msg, tuple):
135 raise NotImplementedError
143 for item
in LOG_LEVELS:
145 (level == item[
'level'])
151 '{}{}{}{}\x1b[0m'.format(
153 item[
'name'].upper(),
debug((str, tuple) msg)
Log debug message colored to console only.
spam((str, tuple) msg)
Log spam message colored to console only.
warning((str, tuple) msg)
Log warning message colored to console only.
notice((str, tuple) msg)
Log notice message colored to console only.
verbose((str, tuple) msg)
Log verbose message colored to console only.
str getMsgText((str, tuple) msg)
Get text string from "msg" object argument.
critical((str, tuple) msg)
Log critical error message colored to console only.
UnexpExcInfo
Named tuple definition of unexpected exception.
printLogToConsole(int level,(str, tuple) msg)
Log leveled and colored message to console only.
initLogging()
Initialize the logging.
success((str, tuple) msg)
Log success message colored to console only.
info((str, tuple) msg)
Log info message colored to console only.
str getExcInfoStr(tuple exc_info)
Parse the exception data for human-readable information.
error((str, tuple) msg)
Log error message colored to console only.