X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2F__init__.py;h=f95b0a906a1fd7c587c9c4f573742f8b4394886b;hb=a301d172e9b7df272a882e88407c8e14cfed2b62;hp=c1010d98c6646dd7a7165fd8474e63aaa5de2792;hpb=4d301304687229c841c15e325474ad946d883ff0;p=yardstick.git diff --git a/yardstick/__init__.py b/yardstick/__init__.py index c1010d98c..f95b0a906 100644 --- a/yardstick/__init__.py +++ b/yardstick/__init__.py @@ -10,15 +10,24 @@ 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 +# include yardstick.common.utils from yardstick.common import constants -from yardstick.common import utils as yardstick_utils -yardstick_utils.makedirs(constants.LOG_DIR) +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 ' - '%(name)s %(filename)s:%(lineno)d ' - '%(levelname)s %(message)s') +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() @@ -36,6 +45,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)