Test case: Fio volume benchmark testcase using job file
[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 '
20                  '%(name)s %(filename)s:%(lineno)d '
21                  '%(levelname)s %(message)s')
22
23 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
24 _LOG_STREAM_HDLR = logging.StreamHandler()
25 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
26
27 LOG = logging.getLogger(__name__)
28
29
30 def _init_logging():
31
32     LOG.setLevel(logging.DEBUG)
33
34     _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER)
35     if os.environ.get('CI_DEBUG', '').lower() in {'1', 'y', "yes", "true"}:
36         _LOG_STREAM_HDLR.setLevel(logging.DEBUG)
37     else:
38         _LOG_STREAM_HDLR.setLevel(logging.INFO)
39     # don't append to log file, clobber
40     _LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER)
41     _LOG_FILE_HDLR.setLevel(logging.DEBUG)
42
43     del logging.root.handlers[:]
44     logging.root.addHandler(_LOG_STREAM_HDLR)
45     logging.root.addHandler(_LOG_FILE_HDLR)
46     logging.debug("logging.root.handlers = %s", logging.root.handlers)