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