From f788f667ca770ff70ce8fca628f1147a1899bf10 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 24 Feb 2018 19:57:46 +0200 Subject: [PATCH] logging: Some performance and memory use optimizations. --- logging/logging.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/logging/logging.py b/logging/logging.py index 1c3ef0d8..1037194f 100644 --- a/logging/logging.py +++ b/logging/logging.py @@ -19,18 +19,24 @@ _stream = sys.stderr class Logger: + level = NOTSET + def __init__(self, name): - self.level = NOTSET self.name = name def _level_str(self, level): - if level in _level_dict: - return _level_dict[level] - return "LVL" + str(level) + l = _level_dict.get(level) + if l is not None: + return l + return "LVL%s" % level def log(self, level, msg, *args): if level >= (self.level or _level): - print(("%s:%s:" + msg) % ((self._level_str(level), self.name) + args), file=_stream) + _stream.write("%s:%s:" % (self._level_str(level), self.name)) + if not args: + print(msg, file=_stream) + else: + print(msg % args, file=_stream) def debug(self, msg, *args): self.log(DEBUG, msg, *args)