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>
This commit is contained in:
parent
404b05ca26
commit
c784c8ecb1
1 changed files with 3 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue