aboutsummaryrefslogtreecommitdiffstats
path: root/functest/core
diff options
context:
space:
mode:
authorJose Lausuch <jose.lausuch@ericsson.com>2017-06-12 23:10:51 +0800
committerjose.lausuch <jose.lausuch@ericsson.com>2017-06-21 13:30:59 +0200
commite900266978e7f02c1999d1095c9d1468d05ea904 (patch)
treea84da875c22c081738c4594354bd7006a1119256 /functest/core
parenta7d07f37d1ea0882d1a92c1e43b0db6a2ed97ede (diff)
Define logger as Feature instance attribute
It allows any Feature subclass to print warning messages in console and debug messages in a dedicated file. Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com> Change-Id: Ic5b1b1184c16cf50f0baadc3904075d0acdf3c6d Signed-off-by: Jose Lausuch <jose.lausuch@ericsson.com> Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/core')
-rw-r--r--functest/core/feature.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/functest/core/feature.py b/functest/core/feature.py
index d53eb7d0..010ff4bc 100644
--- a/functest/core/feature.py
+++ b/functest/core/feature.py
@@ -33,6 +33,24 @@ class Feature(base.TestCase):
super(Feature, self).__init__(**kwargs)
self.result_file = "{}/{}.log".format(
CONST.__getattribute__('dir_results'), self.case_name)
+ try:
+ module = kwargs['run']['module']
+ self.logger = logging.getLogger(module)
+ except KeyError:
+ self.__logger.warning(
+ "Cannot get module name %s. Using %s as fallback",
+ kwargs, self.case_name)
+ self.logger = logging.getLogger(self.case_name)
+ handler = logging.StreamHandler()
+ handler.setLevel(logging.WARN)
+ self.logger.addHandler(handler)
+ handler = logging.FileHandler(self.result_file)
+ handler.setLevel(logging.DEBUG)
+ self.logger.addHandler(handler)
+ formatter = logging.Formatter(
+ '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+ handler.setFormatter(formatter)
+ self.logger.addHandler(handler)
def execute(self, **kwargs):
"""Execute the Python method.