1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from __future__ import absolute_import
15 import yardstick.vTC.apexlake as apexlake
16 from yardstick.common import constants
17 from yardstick.common import utils as yardstick_utils
19 # Hack to be able to run apexlake unit tests
20 # without having to install apexlake.
21 sys.path.append(os.path.dirname(apexlake.__file__))
23 yardstick_utils.makedirs(constants.YARDSTICK_LOG_DIR)
24 LOG_FILE = os.path.join(constants.YARDSTICK_LOG_DIR, 'yardstick.log')
25 LOG_FORMATTER = ('%(asctime)s '
26 '%(name)s %(filename)s:%(lineno)d '
27 '%(levelname)s %(message)s')
29 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
30 _LOG_STREAM_HDLR = logging.StreamHandler()
31 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
33 LOG = logging.getLogger(__name__)
38 LOG.setLevel(logging.DEBUG)
40 _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER)
41 if os.environ.get('CI_DEBUG', '').lower() in {'1', 'y', "yes", "true"}:
42 _LOG_STREAM_HDLR.setLevel(logging.DEBUG)
44 _LOG_STREAM_HDLR.setLevel(logging.INFO)
45 # don't append to log file, clobber
46 _LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER)
47 _LOG_FILE_HDLR.setLevel(logging.DEBUG)
49 del logging.root.handlers[:]
50 logging.root.addHandler(_LOG_STREAM_HDLR)
51 logging.root.addHandler(_LOG_FILE_HDLR)
52 logging.debug("logging.root.handlers = %s", logging.root.handlers)