1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
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 ##############################################################################
10 from __future__ import absolute_import
14 from yardstick.common import constants
15 from yardstick.common import utils as yardstick_utils
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')
23 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
24 _LOG_STREAM_HDLR = logging.StreamHandler()
25 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
27 LOG = logging.getLogger(__name__)
32 LOG.setLevel(logging.DEBUG)
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)
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)
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)