From 77d4dfa984fbf5ab034f9550148e0353b643f0dd Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Tue, 17 Apr 2018 09:48:15 +0200 Subject: Create a static method to configure logger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It helps OPNFV Features to configure their multiple loggers as self.logger is not suitable in case of multiple modules. Change-Id: I5794a3e323d70abfdd85db89a9890488828efd88 Signed-off-by: Cédric Ollivier --- xtesting/core/feature.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'xtesting') diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py index 8474b8a4..ed053e09 100644 --- a/xtesting/core/feature.py +++ b/xtesting/core/feature.py @@ -40,16 +40,21 @@ class Feature(testcase.TestCase): "Cannot get module name %s. Using %s as fallback", kwargs, self.case_name) self.logger = logging.getLogger(self.case_name) + Feature.configure_logger(self.logger, self.result_file) + + @staticmethod + def configure_logger(logger, result_file): + """Configure the logger to print in result_file.""" handler = logging.StreamHandler() handler.setLevel(logging.WARN) - self.logger.addHandler(handler) - handler = logging.FileHandler(self.result_file) + logger.addHandler(handler) + handler = logging.FileHandler(result_file) handler.setLevel(logging.DEBUG) - self.logger.addHandler(handler) + logger.addHandler(handler) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) - self.logger.addHandler(handler) + logger.addHandler(handler) def execute(self, **kwargs): """Execute the Python method. -- cgit 1.2.3-korg