Make lib.App logging more customizable #55

Merged
Jan Lindemann merged 6 commits from jan/feature/20260810-make-lib-app-logging-more-customizable into master 2026-08-10 20:34:59 +02:00 AGit
Showing only changes of commit c784c8ecb1 - Show all commits

lib.log.log(): Use .join() to build argument string

The argument string builder in log() previously iterated with
enumerate and checked per-iteration whether to prepend a space.
Replace the loop with ' '.join(str(a) for a in args), which is a
single C-level operation.

Move the leading-space logic after the only_printable block so the
regex transformations see the raw joined content.

Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann 2026-08-08 20:57:05 +02:00
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -229,13 +229,14 @@ def log( # export
margs = ''
if len(args):
for i, a in enumerate(args):
margs += (' ' if (i or (msg and not msg.endswith(' '))) else '') + str(a)
margs = ' '.join(str(a) for a in args)
if only_printable:
margs = _special_char_regex.sub(
lambda mo: _special_chars[mo.string[mo.start():mo.end()]], margs
)
margs = re.sub('[\x01-\x1f]', '.', margs)
if msg and not msg.endswith(' '):
margs = ' ' + margs
for file in _log_file_streams:
print(msg + _clean_log_prefix + margs, file = file)