mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
adding logging with level and timestamp
This commit is contained in:
parent
01fa6e3322
commit
3a6edb7643
@ -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)
|
||||
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user