X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2F__init__.py;h=e19be36fdb0a0d652fbc5ae68b99d46ad1faf0a9;hb=4ea6acb22260ba5076857136c95a6f9223c9f7c5;hp=7114f8008059331cdae1fb3c437b4fae419480fe;hpb=ea99867bd2a0618aff12ed977330d69467544dfd;p=yardstick.git diff --git a/yardstick/__init__.py b/yardstick/__init__.py index 7114f8008..e19be36fd 100644 --- a/yardstick/__init__.py +++ b/yardstick/__init__.py @@ -7,19 +7,46 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -import logging.config +import os +import sys -logging.basicConfig( - level=logging.WARNING, - format='[%(asctime)s] %(name)-20s %(filename)s:%(lineno)d ' - '%(levelname)s %(message)s', # noqa - datefmt='%m/%d/%y %H:%M:%S') -logging.getLogger(__name__).setLevel(logging.INFO) +import yardstick.vTC.apexlake as apexlake +from yardstick.common import constants +from yardstick.common import utils as yardstick_utils # Hack to be able to run apexlake unit tests # without having to install apexlake. -import sys -import os -import yardstick.vTC.apexlake as apexlake sys.path.append(os.path.dirname(apexlake.__file__)) + +yardstick_utils.makedirs(constants.YARDSTICK_LOG_DIR) +LOG_FILE = os.path.join(constants.YARDSTICK_LOG_DIR, 'yardstick.log') +LOG_FORMATTER = ('%(asctime)s ' + '%(name)s %(filename)s:%(lineno)d ' + '%(levelname)s %(message)s') + +_LOG_FORMATTER = logging.Formatter(LOG_FORMATTER) +_LOG_STREAM_HDLR = logging.StreamHandler() +_LOG_FILE_HDLR = logging.FileHandler(LOG_FILE) + +LOG = logging.getLogger(__name__) + + +def _init_logging(): + + LOG.setLevel(logging.DEBUG) + + _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER) + if os.environ.get('CI_DEBUG', '').lower() in {'1', 'y', "yes", "true"}: + _LOG_STREAM_HDLR.setLevel(logging.DEBUG) + else: + _LOG_STREAM_HDLR.setLevel(logging.INFO) + # don't append to log file, clobber + _LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER) + _LOG_FILE_HDLR.setLevel(logging.DEBUG) + + del logging.root.handlers[:] + logging.root.addHandler(_LOG_STREAM_HDLR) + logging.root.addHandler(_LOG_FILE_HDLR) + logging.debug("logging.root.handlers = %s", logging.root.handlers)