# -*- coding: utf-8 -*-# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-# vi: set ft=python sts=4 ts=4 sw=4 et:importloggingfromwarningsimportwarnimportosimportsysfrom.miscimportstr2booltry:from..external.cloghandlerimportConcurrentRotatingFileHandlerasRFHandlerexceptImportError:# Next 2 lines are optional: issue a warning to the userwarn("ConcurrentLogHandler not installed. Using builtin log handler")fromlogging.handlersimportRotatingFileHandlerasRFHandlerclassLogging(object):"""Nipype logging class"""fmt="%(asctime)s,%(msecs)d%(name)-2s ""%(levelname)-2s:\n\t%(message)s"datefmt="%y%m%d-%H:%M:%S"
[docs]def__init__(self,config):self._config=config# scope our logger to not interfere with user_nipype_logger=logging.getLogger("nipype")_nipype_hdlr=logging.StreamHandler(stream=sys.stdout)_nipype_hdlr.setFormatter(logging.Formatter(fmt=self.fmt,datefmt=self.datefmt))# if StreamHandler was added, do not stackifnotlen(_nipype_logger.handlers):_nipype_logger.addHandler(_nipype_hdlr)self._logger=logging.getLogger("nipype.workflow")self._utlogger=logging.getLogger("nipype.utils")self._fmlogger=logging.getLogger("nipype.filemanip")self._iflogger=logging.getLogger("nipype.interface")self.loggers={"nipype.workflow":self._logger,"nipype.utils":self._utlogger,"nipype.filemanip":self._fmlogger,"nipype.interface":self._iflogger,}self._hdlr=Noneself.update_logging(self._config)
[docs]defgetLogger(self,name):ifname=="filemanip":warn('The "filemanip" logger has been deprecated and replaced by ''the "utils" logger as of nipype 1.0')ifnameinself.loggers:returnself.loggers[name]returnNone
defgetLevelName(self,name):returnlogging.getLevelName(name)deflogdebug_dict_differences(self,dold,dnew,prefix=""):"""Helper to log what actually changed from old to new values of dictionaries. typical use -- log difference for hashed_inputs """from.miscimportdict_diffself._logger.warning("logdebug_dict_differences has been deprecated, please use ""nipype.utils.misc.dict_diff.")self._logger.debug(dict_diff(dold,dnew))