def _set_logger(self, unused=None):
if not hasattr(logging, 'TRACE'):
logging.TRACE = 5
logging.addLevelName(logging.TRACE, "TRACE")
# create a logger, we current use the regular logger but we should
# switch to multiprocessing.get_logger if we notice trouble in, for example,
# logging from multiple processes.
self._logger = logging.getLogger()
# clear previous handler
while self._logger.hasHandlers():
self._logger.removeHandler(self._logger.handlers[0])
self._logger.setLevel(logging.DEBUG)
# output to standard output
cout = logging.StreamHandler()
levels = {
0: logging.ERROR,
1: logging.WARNING,
2: logging.INFO,
3: logging.DEBUG,
4: logging.TRACE,
None: logging.INFO
}
#
cout.setLevel(levels[self._verbosity])
cout.setFormatter(ColoredFormatter('%(color_levelname)s: %(color_msg)s'))
self._logger.addHandler(cout)
self._logger.trace = lambda msg, *args: self._logger._log(logging.TRACE, msg, args)
# output to a log file
if self._logfile is not None:
ch = logging.FileHandler(self._logfile, mode = 'a')
# debug informaiton and time is always written to the log file
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('%(asctime)s: %(levelname)s: %(message)s'))
self._logger.addHandler(ch)
#
# attribute exec_dir
评论列表
文章目录