From 3a6edb7643d2d46db6adccc99c4625b477dc3ae6 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Tue, 28 Feb 2012 17:01:32 +0530 Subject: [PATCH] adding logging with level and timestamp --- tools/testClient/TestCaseExecuteEngine.py | 13 ++++++++++--- tools/testClient/cloudstackTestCase.py | 1 + tools/testClient/deployDataCenter.py | 7 +++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/testClient/TestCaseExecuteEngine.py b/tools/testClient/TestCaseExecuteEngine.py index 059e7556637..cceed9ca8bd 100644 --- a/tools/testClient/TestCaseExecuteEngine.py +++ b/tools/testClient/TestCaseExecuteEngine.py @@ -7,21 +7,30 @@ from functools import partial import os import sys import logging + +module_logger = "testclient.testcase" + def testCaseLogger(message, logger=None): if logger is not None: logger.debug(message) + class TestCaseExecuteEngine(object): def __init__(self, testclient, testCaseFolder, testcaseLogFile=None, testResultLogFile=None): self.testclient = testclient self.testCaseFolder = testCaseFolder self.logger = None if testcaseLogFile is not None: - logger = logging.getLogger("testcase") + logger = logging.getLogger("testclient.testcase.TestCaseExecuteEngine") fh = logging.FileHandler(testcaseLogFile) + fh.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")) logger.addHandler(fh) logger.setLevel(logging.DEBUG) self.logger = logger if testResultLogFile is not None: + ch = logging.StreamHandler() + ch.setLevel(logging.ERROR) + ch.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")) + self.logger.addHandler(ch) fp = open(testResultLogFile, "w") self.testResultLogFile = fp else: @@ -40,5 +49,3 @@ class TestCaseExecuteEngine(object): self.injectTestCase(suite) unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(suite) - - diff --git a/tools/testClient/cloudstackTestCase.py b/tools/testClient/cloudstackTestCase.py index 8625d683cb5..4595aefaa42 100644 --- a/tools/testClient/cloudstackTestCase.py +++ b/tools/testClient/cloudstackTestCase.py @@ -4,6 +4,7 @@ try: except ImportError: import unittest import cloudstackTestClient + class cloudstackTestCase(unittest.case.TestCase): def __init__(self, args): unittest.case.TestCase.__init__(self, args) diff --git a/tools/testClient/deployDataCenter.py b/tools/testClient/deployDataCenter.py index f628d29224e..18684b37621 100644 --- a/tools/testClient/deployDataCenter.py +++ b/tools/testClient/deployDataCenter.py @@ -7,6 +7,8 @@ import logging from cloudstackAPI import * from optparse import OptionParser +module_logger = "testclient.deploy" + class deployDataCenters(): @@ -295,7 +297,7 @@ class deployDataCenters(): self.config = configGenerator.get_setup_config(self.configFile) except: raise cloudstackException.InvalidParameterException( \ - "Failed to load cofig" + sys.exc_info()) + "Failed to load config" + sys.exc_info()) mgt = self.config.mgtSvr[0] @@ -314,8 +316,9 @@ class deployDataCenters(): testClientLogger = None if testClientLogFile is not None: - testClientLogger = logging.getLogger("testClient") + testClientLogger = logging.getLogger("testclient.deploy.deployDataCenters") fh = logging.FileHandler(testClientLogFile) + fh.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")) testClientLogger.addHandler(fh) testClientLogger.setLevel(logging.DEBUG) self.testClientLogger = testClientLogger