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 os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
module_logger = "testclient.testcase"
|
||||||
|
|
||||||
def testCaseLogger(message, logger=None):
|
def testCaseLogger(message, logger=None):
|
||||||
if logger is not None:
|
if logger is not None:
|
||||||
logger.debug(message)
|
logger.debug(message)
|
||||||
|
|
||||||
class TestCaseExecuteEngine(object):
|
class TestCaseExecuteEngine(object):
|
||||||
def __init__(self, testclient, testCaseFolder, testcaseLogFile=None, testResultLogFile=None):
|
def __init__(self, testclient, testCaseFolder, testcaseLogFile=None, testResultLogFile=None):
|
||||||
self.testclient = testclient
|
self.testclient = testclient
|
||||||
self.testCaseFolder = testCaseFolder
|
self.testCaseFolder = testCaseFolder
|
||||||
self.logger = None
|
self.logger = None
|
||||||
if testcaseLogFile is not None:
|
if testcaseLogFile is not None:
|
||||||
logger = logging.getLogger("testcase")
|
logger = logging.getLogger("testclient.testcase.TestCaseExecuteEngine")
|
||||||
fh = logging.FileHandler(testcaseLogFile)
|
fh = logging.FileHandler(testcaseLogFile)
|
||||||
|
fh.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s"))
|
||||||
logger.addHandler(fh)
|
logger.addHandler(fh)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
if testResultLogFile is not None:
|
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")
|
fp = open(testResultLogFile, "w")
|
||||||
self.testResultLogFile = fp
|
self.testResultLogFile = fp
|
||||||
else:
|
else:
|
||||||
@ -40,5 +49,3 @@ class TestCaseExecuteEngine(object):
|
|||||||
self.injectTestCase(suite)
|
self.injectTestCase(suite)
|
||||||
|
|
||||||
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(suite)
|
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(suite)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
import cloudstackTestClient
|
import cloudstackTestClient
|
||||||
|
|
||||||
class cloudstackTestCase(unittest.case.TestCase):
|
class cloudstackTestCase(unittest.case.TestCase):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
unittest.case.TestCase.__init__(self, args)
|
unittest.case.TestCase.__init__(self, args)
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import logging
|
|||||||
from cloudstackAPI import *
|
from cloudstackAPI import *
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
module_logger = "testclient.deploy"
|
||||||
|
|
||||||
|
|
||||||
class deployDataCenters():
|
class deployDataCenters():
|
||||||
|
|
||||||
@ -295,7 +297,7 @@ class deployDataCenters():
|
|||||||
self.config = configGenerator.get_setup_config(self.configFile)
|
self.config = configGenerator.get_setup_config(self.configFile)
|
||||||
except:
|
except:
|
||||||
raise cloudstackException.InvalidParameterException( \
|
raise cloudstackException.InvalidParameterException( \
|
||||||
"Failed to load cofig" + sys.exc_info())
|
"Failed to load config" + sys.exc_info())
|
||||||
|
|
||||||
mgt = self.config.mgtSvr[0]
|
mgt = self.config.mgtSvr[0]
|
||||||
|
|
||||||
@ -314,8 +316,9 @@ class deployDataCenters():
|
|||||||
|
|
||||||
testClientLogger = None
|
testClientLogger = None
|
||||||
if testClientLogFile is not None:
|
if testClientLogFile is not None:
|
||||||
testClientLogger = logging.getLogger("testClient")
|
testClientLogger = logging.getLogger("testclient.deploy.deployDataCenters")
|
||||||
fh = logging.FileHandler(testClientLogFile)
|
fh = logging.FileHandler(testClientLogFile)
|
||||||
|
fh.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s"))
|
||||||
testClientLogger.addHandler(fh)
|
testClientLogger.addHandler(fh)
|
||||||
testClientLogger.setLevel(logging.DEBUG)
|
testClientLogger.setLevel(logging.DEBUG)
|
||||||
self.testClientLogger = testClientLogger
|
self.testClientLogger = testClientLogger
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user