From 893e5eacd33ff8a708cc1286d9386570b64d6f24 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Thu, 25 Sep 2014 17:23:38 -0300 Subject: [PATCH] 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: Lucas Meneghel Rodrigues --- avocado/test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/avocado/test.py b/avocado/test.py index e93b82fa..44238524 100644 --- a/avocado/test.py +++ b/avocado/test.py @@ -140,12 +140,19 @@ class Test(unittest.TestCase): self.logdir = path.init_dir(base_logdir, self.tagged_name) io.set_log_file_dir(self.logdir) 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.sysinfodir = path.init_dir(self.logdir, 'sysinfo') self.sysinfo_logger = sysinfo.SysInfo(basedir=self.sysinfodir) 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.debug('') self.log.debug('Test instance parameters:') @@ -282,6 +289,19 @@ class Test(unittest.TestCase): self.file_handler.setFormatter(formatter) 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): """ Stop the logging activity of the test by cleaning the logger handlers. -- GitLab