From 260df24859a27d0fa63fa9d343fe8ee135f14e29 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Wed, 18 Sep 2019 17:48:37 +0800 Subject: [PATCH] Move pkgset skipping logs to separate file There will be a new log file logs/global/excluding-arch.global.log Fixes: https://pagure.io/pungi/issue/1251 Signed-off-by: Haibo Lin --- pungi/compose.py | 22 ++++++++++++++++++++++ tests/test_compose.py | 2 ++ 2 files changed, 24 insertions(+) diff --git a/pungi/compose.py b/pungi/compose.py index 295f4329..24e88392 100644 --- a/pungi/compose.py +++ b/pungi/compose.py @@ -20,6 +20,7 @@ __all__ = ( import errno +import logging import os import time import tempfile @@ -128,6 +129,27 @@ class Compose(kobo.log.LoggingBase): # Set up logging to file if logger: kobo.log.add_file_logger(logger, self.paths.log.log_file("global", "pungi.log")) + kobo.log.add_file_logger(logger, self.paths.log.log_file("global", "excluding-arch.log")) + + class PungiLogFilter(logging.Filter): + def filter(self, record): + return False if record.funcName and record.funcName == 'is_excluded' else True + + class ExcludingArchLogFilter(logging.Filter): + def filter(self, record): + if 'Populating package set for arch:' in record.message or \ + (record.funcName and record.funcName == 'is_excluded'): + return True + else: + return False + + for handler in logger.handlers: + if isinstance(handler, logging.FileHandler): + log_file_name = os.path.basename(handler.stream.name) + if log_file_name == 'pungi.global.log': + handler.addFilter(PungiLogFilter()) + elif log_file_name == 'excluding-arch.global.log': + handler.addFilter(ExcludingArchLogFilter()) # to provide compose_id, compose_date and compose_respin self.ci_base = ComposeInfo() diff --git a/tests/test_compose.py b/tests/test_compose.py index cd9638d7..a1bdde8c 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -369,6 +369,7 @@ class ComposeTestCase(unittest.TestCase): ci.return_value.compose.type_suffix = '.n' logger = mock.Mock() + logger.handlers = [] conf = ConfigWrapper( variants_file={'scm': 'file', @@ -433,6 +434,7 @@ class StatusTest(unittest.TestCase): def setUp(self): self.tmp_dir = tempfile.mkdtemp() self.logger = mock.Mock() + self.logger.handlers = [] with mock.patch('pungi.compose.ComposeInfo'): self.compose = Compose({}, self.tmp_dir, logger=self.logger)