From ea1bcf625b1cb26c02f81e095bb835945876357a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 4 Nov 2016 09:01:58 +0100 Subject: [PATCH] pungi: Only add logger once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Pungi object reuses the same logger for all its instances. Every time a new instance is created, a stream handler would be added. This means that a second instance will print everything twice. When running tests, tens of instances would be created. This patch only adds the handler if there are no handlers configured yet. Signed-off-by: Lubomír Sedlář --- pungi/gather.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pungi/gather.py b/pungi/gather.py index 6ed07a9a..03a2cc33 100644 --- a/pungi/gather.py +++ b/pungi/gather.py @@ -214,12 +214,13 @@ class Pungi(PungiBase): lock = lockfile.LockFile(filename) self.yumlock = ReentrantYumLock(lock, self.logger) - # Create the stdout/err streams and only send INFO+ stuff there - formatter = logging.Formatter('%(name)s:%(levelname)s: %(message)s') - console = logging.StreamHandler() - console.setFormatter(formatter) - console.setLevel(logging.INFO) - self.logger.addHandler(console) + if not self.logger.handlers: + # Create the stdout/err streams and only send INFO+ stuff there + formatter = logging.Formatter('%(name)s:%(levelname)s: %(message)s') + console = logging.StreamHandler() + console.setFormatter(formatter) + console.setLevel(logging.INFO) + self.logger.addHandler(console) self.destdir = self.config.get('pungi', 'destdir') self.archdir = os.path.join(self.destdir,