From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C920FC320 for ; Fri, 22 May 2015 11:04:45 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 22 May 2015 02:04:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,474,1427785200"; d="scan'208";a="730110175" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 22 May 2015 02:04:44 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t4M94gl6003056; Fri, 22 May 2015 17:04:42 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t4M94ebs014398; Fri, 22 May 2015 17:04:42 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t4M94eTV014394; Fri, 22 May 2015 17:04:40 +0800 From: "Jiajia, Sun" To: dts@dpdk.org Date: Fri, 22 May 2015 17:04:04 +0800 Message-Id: <1432285452-14286-12-git-send-email-sunx.jiajia@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1432285452-14286-1-git-send-email-sunx.jiajia@intel.com> References: <1432285452-14286-1-git-send-email-sunx.jiajia@intel.com> Subject: [dts] [PATCH v2 11/19] Add some codes to support virtual test log X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 May 2015 09:04:46 -0000 From: sjiajiax Signed-off-by: sjiajiax --- framework/logger.py | 69 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/framework/logger.py b/framework/logger.py index 1829e18..5597e33 100644 --- a/framework/logger.py +++ b/framework/logger.py @@ -35,6 +35,9 @@ import sys import inspect import re +from settings import LOG_NAME_SEP +from utils import RED + """ DTS logger module with several log level. DTS framwork and TestSuite log will saved into different log files. @@ -58,6 +61,9 @@ logging.SUITE_TESTER_OUTPUT = logging.DEBUG + 4 logging.DTS_IXIA_CMD = logging.INFO + 5 logging.DTS_IXIA_OUTPUT = logging.DEBUG + 5 +logging.DTS_VIRTDUT_CMD = logging.INFO + 6 +logging.DTS_VIRTDUT_OUTPUT = logging.DEBUG + 6 + logging.addLevelName(logging.DTS_DUT_CMD, 'DTS_DUT_CMD') logging.addLevelName(logging.DTS_DUT_OUTPUT, 'DTS_DUT_OUTPUT') logging.addLevelName(logging.DTS_DUT_RESULT, 'DTS_DUT_RESUTL') @@ -66,6 +72,12 @@ logging.addLevelName(logging.DTS_TESTER_CMD, 'DTS_TESTER_CMD') logging.addLevelName(logging.DTS_TESTER_OUTPUT, 'DTS_TESTER_OUTPUT') logging.addLevelName(logging.DTS_TESTER_RESULT, 'DTS_TESTER_RESULT') +logging.addLevelName(logging.DTS_IXIA_CMD, 'DTS_IXIA_CMD') +logging.addLevelName(logging.DTS_IXIA_OUTPUT, 'DTS_IXIA_OUTPUT') + +logging.addLevelName(logging.DTS_VIRTDUT_CMD, 'VIRTDUT_CMD') +logging.addLevelName(logging.DTS_VIRTDUT_OUTPUT, 'VIRTDUT_OUTPUT') + logging.addLevelName(logging.SUITE_DUT_CMD, 'SUITE_DUT_CMD') logging.addLevelName(logging.SUITE_DUT_OUTPUT, 'SUITE_DUT_OUTPUT') @@ -82,15 +94,18 @@ stream_fmt = '%(color)s%(levelname)20s: %(message)s' + RESET_COLOR log_dir = None -def RED(text): - return "\x1B[" + "31;1m" + text + "\x1B[" + "0m" - - def set_verbose(): global verbose verbose = True +def add_salt(salt, msg): + if not salt: + return msg + else: + return '[%s] ' % salt + str(msg) + + class BaseLoggerAdapter(logging.LoggerAdapter): """ Upper layer of original logging module. @@ -132,6 +147,12 @@ class BaseLoggerAdapter(logging.LoggerAdapter): def dts_ixia_output(self, msg, *args, **kwargs): self.log(logging.DTS_IXIA_OUTPUT, msg, *args, **kwargs) + def dts_virtdut_cmd(self, msg, *args, **kwargs): + self.log(logging.DTS_VIRTDUT_CMD, msg, *args, **kwargs) + + def dts_virtdut_output(self, msg, *args, **kwargs): + self.log(logging.DTS_VIRTDUT_OUTPUT, msg, *args, **kwargs) + class ColorHandler(logging.StreamHandler): """ @@ -150,6 +171,8 @@ class ColorHandler(logging.StreamHandler): logging.SUITE_TESTER_CMD: '', # SYSTEM logging.DTS_IXIA_CMD: '', # SYSTEM logging.DTS_IXIA_OUTPUT: '', # SYSTEM + logging.DTS_VIRTDUT_CMD: '', # SYSTEM + logging.DTS_VIRTDUT_OUTPUT: '', # SYSTEM logging.WARN: '\033[01;33m', # BOLD YELLOW logging.DTS_DUT_RESULT: '\033[01;34m', # BOLD BLUE logging.DTS_TESTER_RESULT: '\033[01;34m', # BOLD BLUE @@ -189,6 +212,8 @@ class DTSLOG(BaseLoggerAdapter): self.crb = crb super(DTSLOG, self).__init__(self.logger, dict(crb=self.crb)) + self.salt = '' + self.fh = None self.ch = None @@ -221,24 +246,28 @@ class DTSLOG(BaseLoggerAdapter): """ DTS warnning level log function. """ + message = add_salt(self.salt, message) self.logger.log(self.warn_lvl, message) def info(self, message): """ DTS information level log function. """ + message = add_salt(self.salt, message) self.logger.log(self.info_lvl, message) def error(self, message): """ DTS error level log function. """ + message = add_salt(self.salt, message) self.logger.log(self.error_lvl, message) def debug(self, message): """ DTS debug level log function. """ + message = add_salt(self.salt, message) self.logger.log(self.debug_lvl, message) def set_logfile_path(self, path): @@ -270,17 +299,34 @@ class DTSLOG(BaseLoggerAdapter): ch = ColorHandler() self.__log_hander(fh, ch) - if crb == "dut": + def set_salt(crb, start_flag): + if LOG_NAME_SEP in crb: + old = '%s%s' % (start_flag, LOG_NAME_SEP) + if not self.salt: + self.salt = crb.replace(old, '', 1) + + if crb.startswith('dut'): self.info_lvl = logging.DTS_DUT_CMD self.debug_lvl = logging.DTS_DUT_OUTPUT self.warn_lvl = logging.DTS_DUT_RESULT - elif crb == "tester": + + set_salt(crb, 'dut') + elif crb.startswith('tester'): self.info_lvl = logging.DTS_TESTER_CMD self.debug_lvl = logging.DTS_TESTER_OUTPUT self.warn_lvl = logging.DTS_TESTER_RESULT - elif crb == "ixia": + + set_salt(crb, 'tester') + elif crb.startswith('ixia'): self.info_lvl = logging.DTS_IXIA_CMD self.debug_lvl = logging.DTS_IXIA_OUTPUT + + set_salt(crb, 'ixia') + elif crb.startswith('virtdut'): + self.info_lvl = logging.DTS_VIRTDUT_CMD + self.debug_lvl = logging.DTS_VIRTDUT_OUTPUT + + set_salt(crb, 'virtdut') else: self.error_lvl = logging.ERROR self.warn_lvl = logging.WARNING @@ -296,15 +342,18 @@ class DTSLOG(BaseLoggerAdapter): ch = ColorHandler() self.__log_hander(fh, ch) - if crb == "dut": + if crb == 'dut': self.info_lvl = logging.SUITE_DUT_CMD self.debug_lvl = logging.SUITE_DUT_OUTPUT - elif crb == "tester": + elif crb == 'tester': self.info_lvl = logging.SUITE_TESTER_CMD self.debug_lvl = logging.SUITE_TESTER_OUTPUT - elif crb == "ixia": + elif crb == 'ixia': self.info_lvl = logging.DTS_IXIA_CMD self.debug_lvl = logging.DTS_IXIA_OUTPUT + elif crb == 'virtdut': + self.info_lvl = logging.DTS_VIRTDUT_CMD + self.debug_lvl = logging.DTS_VIRTDUT_OUTPUT def logger_exit(self): """ -- 1.9.3