Merge "Add smoke, components, features and performance test suite for Yatdstick"
[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 import logging
11 import os
12 import sys
13
14 import yardstick.vTC.apexlake as apexlake
15
16 # Hack to be able to run apexlake unit tests
17 # without having to install apexlake.
18 sys.path.append(os.path.dirname(apexlake.__file__))
19
20 LOG_FILE = '/tmp/yardstick.log'
21 LOG_FORMATTER = ('%(asctime)s '
22                  '%(name)s %(filename)s:%(lineno)d '
23                  '%(levelname)s %(message)s')
24
25 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
26 _LOG_STREAM_HDLR = logging.StreamHandler()
27 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
28
29 LOG = logging.getLogger(__name__)
30
31
32 def _init_logging():
33
34     _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER)
35
36     # don't append to log file, clobber
37     _LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER)
38
39     del logging.root.handlers[:]
40     logging.root.addHandler(_LOG_STREAM_HDLR)
41     logging.root.addHandler(_LOG_FILE_HDLR)
42     logging.debug("logging.root.handlers = %s", logging.root.handlers)
43
44     if os.environ.get('CI_DEBUG', '').lower() in {'1', 1, 'y', "yes", "true"}:
45         LOG.setLevel(logging.DEBUG)
46     else:
47         LOG.setLevel(logging.INFO)