Merge "Add nodeSelector to enable selecting the desired Kubernetes running node when...
[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
14 from yardstick.common import constants
15 from yardstick.common import utils as yardstick_utils
16
17 yardstick_utils.makedirs(constants.LOG_DIR)
18 LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log')
19 LOG_FORMATTER = '%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d %(message)s'
20
21 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
22 _LOG_STREAM_HDLR = logging.StreamHandler()
23 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
24
25 LOG = logging.getLogger(__name__)
26
27
28 def _init_logging():
29
30     LOG.setLevel(logging.DEBUG)
31
32     _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER)
33     if os.environ.get('CI_DEBUG', '').lower() in {'1', 'y', "yes", "true"}:
34         _LOG_STREAM_HDLR.setLevel(logging.DEBUG)
35     else:
36         _LOG_STREAM_HDLR.setLevel(logging.INFO)
37     # don't append to log file, clobber
38     _LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER)
39     _LOG_FILE_HDLR.setLevel(logging.DEBUG)
40
41     del logging.root.handlers[:]
42     logging.root.addHandler(_LOG_STREAM_HDLR)
43     logging.root.addHandler(_LOG_FILE_HDLR)
44     logging.debug("logging.root.handlers = %s", logging.root.handlers)