B ÔÂ_Ó ã@s`ddlZddlmZddlmZe d¡Ze eedd„d�¡e ej ¡Gdd „d e ƒZ dS) éN)Ú LogHandler)ÚPYOMO_ROOT_DIRZpyomocCs t tj¡S)N)Ú_loggerÚ isEnabledForÚloggingÚDEBUG©rrú4/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/common/log.pyÚór )Ú verbosityc@s0eZdZdZdejfdd„Zdd„Zdd„ZdS) ÚLoggingInterceptaÌContext manager for intercepting messages sent to a log stream This class is designed to enable easy testing of log messages. The LoggingIntercept context manager will intercept messages sent to a log stream matching a specified level and send the messages to the specified output stream. Other handlers registered to the target logger will be temporarily removed and the logger will be set not to propagate messages up to higher-level loggers. Args: output (FILE): the file stream to send log messages to module (str): the target logger name to intercept level (int): the logging level to intercept Examples: >>> import six, logging >>> from pyomo.common.log import LoggingIntercept >>> buf = six.StringIO() >>> with LoggingIntercept(buf, 'pyomo.core', logging.WARNING): ... logging.getLogger('pyomo.core').warning('a simple message') >>> buf.getvalue() NcCs:t |¡|_|j t d¡¡|j |¡||_d|_dS)Nz %(message)s)rÚ StreamHandlerÚhandlerÚ setFormatterÚ FormatterÚsetLevelÚmoduleÚ_save)ÚselfÚoutputrÚlevelrrr Ú__init__6s   zLoggingIntercept.__init__cCsHt |j¡}|j|j|jf|_g|_d|_| |jj¡|  |j¡dS)Nr) rÚ getLoggerrrÚ propagateÚhandlersrrrÚ addHandler)rÚloggerrrr Ú __enter__=s  zLoggingIntercept.__enter__cCsXt |j¡}| |j¡| |jd¡|jd|_x|jdD]}|j  |¡q@WdS)Nréé) rrrÚ removeHandlerrrrrrÚappend)rÚetZevÚtbrÚhrrr Ú__exit__Es    zLoggingIntercept.__exit__) Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚWARNINGrrr&rrrr r sr ) rZ pyutilib.miscrZpyomo.common.fileutilsrrrrrr+Úobjectr rrrr Ús