Improve Yardstick user-guide
[yardstick.git] / yardstick / __init__.py
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 #
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 ##############################################################################
9
10 from __future__ import absolute_import
11 import logging
12 import os
13 import sys
14
15 import yardstick.vTC.apexlake as apexlake
16 from yardstick.common import constants
17 from yardstick.common import utils as yardstick_utils
18
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__))
22
23 yardstick_utils.makedirs(constants.LOG_DIR)
24 LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log')
25 LOG_FORMATTER = ('%(asctime)s '
26                  '%(name)s %(filename)s:%(lineno)d '
27                  '%(levelname)s %(message)s')
28
29 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
30 _LOG_STREAM_HDLR = logging.StreamHandler()
31 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
32
33 LOG = logging.getLogger(__name__)
34
35
36 def _init_logging():
37
38     LOG.setLevel(logging.DEBUG)
39
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)
43     else:
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)
48
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)