diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-04-17 09:48:15 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-04-17 15:39:22 +0200 |
commit | 10fb4290265024cb4482f2b88ac6b4a53c83ec7f (patch) | |
tree | 9f5fe8c2897cc71b03072dc64f118a7447d41a40 | |
parent | a046ec1f2ef3c35e956dba97e63f7cc8a27a346c (diff) |
Create a static method to configure logger
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 <cedric.ollivier@orange.com>
(cherry picked from commit 77d4dfa984fbf5ab034f9550148e0353b643f0dd)
-rw-r--r-- | xtesting/core/feature.py | 13 |
1 files changed, 9 insertions, 4 deletions
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. |