2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
22 from utils.parser import Parser as conf_parser
23 conf_parser.config_init()
27 def __init__(self, logger_name):
29 # if user set --debug as a cli parameter
30 # we will set this variable "Debug" to output debug info.
31 DEBUG = os.getenv('DEBUG')
33 self.logger = logging.getLogger(logger_name)
34 self.logger.propagate = 0
35 self.logger.setLevel(logging.DEBUG)
37 ch = logging.StreamHandler()
38 log_formatter = ('%(asctime)s '
39 '%(filename)s:%(lineno)d '
40 '%(levelname)s %(message)s')
42 formatter = logging.Formatter(log_formatter)
44 ch.setFormatter(formatter)
45 if DEBUG is not None and DEBUG.lower() == "true":
46 ch.setLevel(logging.DEBUG)
48 ch.setLevel(logging.INFO)
49 self.logger.addHandler(ch)
51 result_path = conf_parser.bottlenecks_config["log_dir"]
52 if not os.path.exists(result_path):
53 os.makedirs(result_path)
54 result_file = os.path.join(result_path, 'bottlenecks.log')
55 hdlr = logging.FileHandler(result_file)
57 hdlr.setFormatter(formatter)
58 hdlr.setLevel(logging.DEBUG)
59 self.logger.addHandler(hdlr)