X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2F__init__.py;h=9eb5db9b16b2654336dcb20792c7746f75b8eb6a;hb=refs%2Fheads%2Fstable%2Fgambia;hp=b673e7c4a9a56783e963f39be7f639067ed01009;hpb=b3c51ed384eb538f1458512dbab312c53d6de134;p=yardstick.git diff --git a/yardstick/__init__.py b/yardstick/__init__.py index b673e7c4a..9eb5db9b1 100644 --- a/yardstick/__init__.py +++ b/yardstick/__init__.py @@ -10,11 +10,23 @@ from __future__ import absolute_import import logging import os +import errno +# 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 + + +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 -yardstick_utils.makedirs(constants.LOG_DIR) LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log') LOG_FORMATTER = '%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d %(message)s' @@ -34,6 +46,7 @@ def _init_logging(): _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)