lib.log.log(): Fix superfluous message whitespace

When prefix flags (position, prio, date) are combined with message
arguments, log() would double-space the output (e.g. '<N>  Created')
or omit the separator entirely (e.g. '<N>Created'). The root cause
was that log() prepended a space to every argument, regardless of
whether the prefix already ended with one.

Fix: only prepend a space before the first argument when the prefix
doesn't already end with one. This produces exactly one separator
between prefix and content regardless of which flags are active.

Also fix log_m(): skip empty strings (the sentinel '') so it doesn't
contribute a space. And fix the early return that dropped messages
when no prefix flags were set (previous commit).

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-08-08 20:53:54 +02:00
commit 404b05ca26
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -181,6 +181,8 @@ def log_m(prio: int, *args: Any, **kwargs: Any) -> None: # export
if isinstance(a, list):
margs += '\n'.join([str(elem) for elem in a])
continue
if a == '':
continue
margs += ' ' + str(a)
if 'caller' not in kwargs:
caller = get_caller_pos(1)
@ -205,7 +207,7 @@ def log( # export
color_off = ''
if f_date in _flags:
msg += datetime.now().strftime("%b %d %H:%M:%S.%f ")
msg += datetime.now().strftime("%b %d %H:%M:%S.%f") + ' '
if f_prio in _flags:
msg += _short_prio_str[prio] + ' '
@ -227,8 +229,8 @@ def log( # export
margs = ''
if len(args):
for a in args:
margs += ' ' + str(a)
for i, a in enumerate(args):
margs += (' ' if (i or (msg and not msg.endswith(' '))) else '') + str(a)
if only_printable:
margs = _special_char_regex.sub(
lambda mo: _special_chars[mo.string[mo.start():mo.end()]], margs