X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2F__init__.py;h=9eb5db9b16b2654336dcb20792c7746f75b8eb6a;hb=refs%2Fchanges%2F51%2F60951%2F7;hp=fbbc101a93b7ba7807673239b80b61023d69b0ee;hpb=d292f1a4d00640ea6436d6d41eba5d03aea46a78;p=yardstick.git diff --git a/yardstick/__init__.py b/yardstick/__init__.py index fbbc101a9..9eb5db9b1 100644 --- a/yardstick/__init__.py +++ b/yardstick/__init__.py @@ -10,21 +10,25 @@ from __future__ import absolute_import import logging import os -import sys +import errno -import yardstick.vTC.apexlake as apexlake +# this module must only import other modules that do +# not require loggers to be created, so this cannot from yardstick.common import constants -from yardstick.common import utils as yardstick_utils +from yardstick.common import exceptions -# Hack to be able to run apexlake unit tests -# without having to install 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') +try: + # do not use yardstick.common.utils.makedirs + # since yardstick.common.utils creates a logger + # and so it cannot be imported before this code + os.makedirs(constants.LOG_DIR) +except OSError as e: + if e.errno != errno.EEXIST: + raise + +LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log') +LOG_FORMATTER = '%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d %(message)s' _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER) _LOG_STREAM_HDLR = logging.StreamHandler() @@ -35,17 +39,19 @@ 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) - - if os.environ.get('CI_DEBUG', '').lower() in {'1', 1, 'y', "yes", "true"}: - LOG.setLevel(logging.DEBUG) - else: - LOG.setLevel(logging.INFO)