mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
log.py: Add slog_m() (multiline logging)
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
1cdb38b767
commit
036a978130
1 changed files with 21 additions and 4 deletions
|
|
@ -75,6 +75,17 @@ def get_caller_pos(up = 1):
|
||||||
caller_frame = inspect.currentframe().f_back.f_back
|
caller_frame = inspect.currentframe().f_back.f_back
|
||||||
return (basename(caller_frame.f_code.co_filename), caller_frame.f_lineno)
|
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
|
def slog(prio, *args, **kwargs): # export
|
||||||
|
|
||||||
if prio > _level:
|
if prio > _level:
|
||||||
|
|
@ -83,7 +94,6 @@ def slog(prio, *args, **kwargs): # export
|
||||||
msg = ''
|
msg = ''
|
||||||
color_on = ''
|
color_on = ''
|
||||||
color_off = ''
|
color_off = ''
|
||||||
file = sys.stderr
|
|
||||||
|
|
||||||
if f_prio in _flags:
|
if f_prio in _flags:
|
||||||
msg += _short_prio_str[prio] + ' '
|
msg += _short_prio_str[prio] + ' '
|
||||||
|
|
@ -104,13 +114,20 @@ def slog(prio, *args, **kwargs): # export
|
||||||
margs += ' ' + str(a)
|
margs += ' ' + str(a)
|
||||||
msg += color_on + margs + color_off
|
msg += color_on + margs + color_off
|
||||||
|
|
||||||
|
if not len(msg):
|
||||||
|
return
|
||||||
|
|
||||||
|
files = []
|
||||||
if f_stdout in _flags:
|
if f_stdout in _flags:
|
||||||
file = sys.stdout
|
files.append(sys.stdout)
|
||||||
|
|
||||||
if f_stderr in _flags:
|
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)
|
print(msg, file=file)
|
||||||
|
|
||||||
def parse_log_prio_str(prio): # export
|
def parse_log_prio_str(prio): # export
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue