From 404b05ca262152dbd02825f041923cdef6af5ad6 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 8 Aug 2026 20:53:54 +0200 Subject: [PATCH] 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. ' Created') or omit the separator entirely (e.g. '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 --- src/python/jw/pkg/lib/log.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/python/jw/pkg/lib/log.py b/src/python/jw/pkg/lib/log.py index ee636f72..57f38b09 100644 --- a/src/python/jw/pkg/lib/log.py +++ b/src/python/jw/pkg/lib/log.py @@ -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