avocado.test: Create the 'stdout.actual' and 'stderr.actual' files for tests

Create the file handler for both streams and connect them to
the loggers, so whatever goes on the stdout of those tests
will be logged to those files.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 6fc89e26
...@@ -140,12 +140,19 @@ class Test(unittest.TestCase): ...@@ -140,12 +140,19 @@ class Test(unittest.TestCase):
self.logdir = path.init_dir(base_logdir, self.tagged_name) self.logdir = path.init_dir(base_logdir, self.tagged_name)
io.set_log_file_dir(self.logdir) io.set_log_file_dir(self.logdir)
self.logfile = os.path.join(self.logdir, 'debug.log') self.logfile = os.path.join(self.logdir, 'debug.log')
self.stdout_file = os.path.join(self.logdir, 'stdout.actual')
self.stderr_file = os.path.join(self.logdir, 'stderr.actual')
self.outputdir = path.init_dir(self.logdir, 'data') self.outputdir = path.init_dir(self.logdir, 'data')
self.sysinfodir = path.init_dir(self.logdir, 'sysinfo') self.sysinfodir = path.init_dir(self.logdir, 'sysinfo')
self.sysinfo_logger = sysinfo.SysInfo(basedir=self.sysinfodir) self.sysinfo_logger = sysinfo.SysInfo(basedir=self.sysinfodir)
self.log = logging.getLogger("avocado.test") self.log = logging.getLogger("avocado.test")
self.stdout_log = logging.getLogger("avocado.test.stdout")
self.stderr_log = logging.getLogger("avocado.test.stderr")
self.log.info('START %s', self.tagged_name) self.log.info('START %s', self.tagged_name)
self.log.debug('') self.log.debug('')
self.log.debug('Test instance parameters:') self.log.debug('Test instance parameters:')
...@@ -282,6 +289,19 @@ class Test(unittest.TestCase): ...@@ -282,6 +289,19 @@ class Test(unittest.TestCase):
self.file_handler.setFormatter(formatter) self.file_handler.setFormatter(formatter)
self.log.addHandler(self.file_handler) self.log.addHandler(self.file_handler)
stream_fmt = '%(message)s'
stream_formatter = logging.Formatter(fmt=stream_fmt)
self.stdout_file_handler = logging.FileHandler(filename=self.stdout_file)
self.stdout_file_handler.setLevel(logging.DEBUG)
self.stdout_file_handler.setFormatter(stream_formatter)
self.stdout_log.addHandler(self.stdout_file_handler)
self.stderr_file_handler = logging.FileHandler(filename=self.stderr_file)
self.stderr_file_handler.setLevel(logging.DEBUG)
self.stderr_file_handler.setFormatter(stream_formatter)
self.stderr_log.addHandler(self.stderr_file_handler)
def stop_logging(self): def stop_logging(self):
""" """
Stop the logging activity of the test by cleaning the logger handlers. Stop the logging activity of the test by cleaning the logger handlers.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册