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 <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2019-09-18 17:48:37 +08:00
parent 150f5f0cb6
commit 260df24859
2 changed files with 24 additions and 0 deletions

View File

@ -20,6 +20,7 @@ __all__ = (
import errno import errno
import logging
import os import os
import time import time
import tempfile import tempfile
@ -128,6 +129,27 @@ class Compose(kobo.log.LoggingBase):
# Set up logging to file # Set up logging to file
if logger: 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", "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 # to provide compose_id, compose_date and compose_respin
self.ci_base = ComposeInfo() self.ci_base = ComposeInfo()

View File

@ -369,6 +369,7 @@ class ComposeTestCase(unittest.TestCase):
ci.return_value.compose.type_suffix = '.n' ci.return_value.compose.type_suffix = '.n'
logger = mock.Mock() logger = mock.Mock()
logger.handlers = []
conf = ConfigWrapper( conf = ConfigWrapper(
variants_file={'scm': 'file', variants_file={'scm': 'file',
@ -433,6 +434,7 @@ class StatusTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmp_dir = tempfile.mkdtemp() self.tmp_dir = tempfile.mkdtemp()
self.logger = mock.Mock() self.logger = mock.Mock()
self.logger.handlers = []
with mock.patch('pungi.compose.ComposeInfo'): with mock.patch('pungi.compose.ComposeInfo'):
self.compose = Compose({}, self.tmp_dir, logger=self.logger) self.compose = Compose({}, self.tmp_dir, logger=self.logger)