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