1 ##############################################################################
2 # Copyright (c) 2016 ZTE Corporation 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 # import doctor_logger
11 # logger = doctor_logger.Logger("script_name").getLogger()
12 # logger.info("message to be shown with - INFO - ")
13 # logger.debug("message to be shown with - DEBUG -")
20 def __init__(self, logger_name):
22 CI_DEBUG = os.getenv('CI_DEBUG')
24 logging.basicConfig(filemode='w')
25 self.logger = logging.getLogger(logger_name)
26 self.logger.propagate = 0
27 self.logger.setLevel(logging.DEBUG)
29 formatter = logging.Formatter('%(asctime)s %(filename)s %(lineno)d '
30 '%(levelname)-6s %(message)s')
32 ch = logging.StreamHandler()
33 ch.setFormatter(formatter)
34 if CI_DEBUG is not None and CI_DEBUG.lower() == "true":
35 ch.setLevel(logging.DEBUG)
37 ch.setLevel(logging.INFO)
38 self.logger.addHandler(ch)
40 file_handler = logging.FileHandler('%s.log' % logger_name)
41 file_handler.setFormatter(formatter)
42 file_handler.setLevel(logging.DEBUG)
43 self.logger.addHandler(file_handler)