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
15 # this module must only import other modules that do
16 # not require loggers to be created, so this cannot
17 # include yardstick.common.utils
18 from yardstick.common import constants
21 # do not use yardstick.common.utils.makedirs
22 # since yardstick.common.utils creates a logger
23 # and so it cannot be imported before this code
24 os.makedirs(constants.LOG_DIR)
26 if e.errno != errno.EEXIST:
29 LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log')
30 LOG_FORMATTER = '%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d %(message)s'
32 _LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
33 _LOG_STREAM_HDLR = logging.StreamHandler()
34 _LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)
36 LOG = logging.getLogger(__name__)
41 LOG.setLevel(logging.DEBUG)
43 _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER)
44 if os.environ.get('CI_DEBUG', '').lower() in {'1', 'y', "yes", "true"}:
45 _LOG_STREAM_HDLR.setLevel(logging.DEBUG)
47 _LOG_STREAM_HDLR.setLevel(logging.INFO)
49 # don't append to log file, clobber
50 _LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER)
51 _LOG_FILE_HDLR.setLevel(logging.DEBUG)
53 del logging.root.handlers[:]
54 logging.root.addHandler(_LOG_STREAM_HDLR)
55 logging.root.addHandler(_LOG_FILE_HDLR)
56 logging.debug("logging.root.handlers = %s", logging.root.handlers)