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 bottlenecks_cfg import Bottlenecks_cfg as bn_cfg
26 def __init__(self, logger_name):
28 #if user set --debug as a cli parameter
29 #we will set this variable “Debug” to output debug info.
30 DEBUG = os.getenv('DEBUG')
32 self.logger = logging.getLogger(logger_name)
33 self.logger.propagate = 0
34 self.logger.setLevel(logging.DEBUG)
36 ch = logging.StreamHandler()
37 log_formatter = ('%(asctime)s '
38 '%(name)s %(filename)s:%(lineno)d '
39 '%(levelname)s %(message)s')
41 formatter = logging.Formatter(log_formatter)
43 ch.setFormatter(formatter)
44 if DEBUG is not None and DEBUG.lower() == "true":
45 ch.setLevel(logging.DEBUG)
47 ch.setLevel(logging.INFO)
48 self.logger.addHandler(ch)
50 # result_path = bn_cfg.['log_dir']
51 # if not os.path.exists(result_path):
52 # os.makedirs(result_path)
53 hdlr = logging.FileHandler('/tmp/bottlenecks.log')
54 hdlr.setFormatter(formatter)
55 hdlr.setLevel(logging.DEBUG)
56 self.logger.addHandler(hdlr)