log.py: Add slog_m() (multiline logging)

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2019-10-28 12:50:17 +01:00
commit 036a978130

View file

@ -75,6 +75,17 @@ def get_caller_pos(up = 1):
caller_frame = inspect.currentframe().f_back.f_back
return (basename(caller_frame.f_code.co_filename), caller_frame.f_lineno)
def slog_m(prio, *args, **kwargs): # export
if prio > _level:
return
if len(args):
margs = ''
for a in args:
margs += ' ' + str(a)
caller = get_caller_pos(1)
for line in margs[1:].split('\n'):
slog(prio, line, **kwargs, caller=caller)
def slog(prio, *args, **kwargs): # export
if prio > _level:
@ -83,7 +94,6 @@ def slog(prio, *args, **kwargs): # export
msg = ''
color_on = ''
color_off = ''
file = sys.stderr
if f_prio in _flags:
msg += _short_prio_str[prio] + ' '
@ -104,13 +114,20 @@ def slog(prio, *args, **kwargs): # export
margs += ' ' + str(a)
msg += color_on + margs + color_off
if not len(msg):
return
files = []
if f_stdout in _flags:
file = sys.stdout
files.append(sys.stdout)
if f_stderr in _flags:
file = sys.stderr
files.append(sys.stderr)
if len(msg):
if not len(files):
files = [ sys.stdout ]
for file in files:
print(msg, file=file)
def parse_log_prio_str(prio): # export