B _ @s`ddlZddlmZddlmZedZeeedddeej Gdd d e Z dS) N) LogHandler)PYOMO_ROOT_DIRZpyomocCs ttjS)N)_logger isEnabledForloggingDEBUGrr4/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/common/log.pyr ) verbosityc@s0eZdZdZdejfddZddZddZdS) LoggingInterceptaContext 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||_|jtd|j|||_d|_dS)Nz %(message)s)r StreamHandlerhandler setFormatter FormattersetLevelmodule_save)selfoutputrlevelrrr __init__6s   zLoggingIntercept.__init__cCsHt|j}|j|j|jf|_g|_d|_||jj| |jdS)Nr) r getLoggerrr propagatehandlersrrr addHandler)rloggerrrr __enter__=s  zLoggingIntercept.__enter__cCsXt|j}||j||jd|jd|_x|jdD]}|j |q@WdS)Nr) rrr removeHandlerrrrrrappend)retZevtbrhrrr __exit__Es    zLoggingIntercept.__exit__) __name__ __module__ __qualname____doc__rWARNINGrrr&rrrr r sr ) rZ pyutilib.miscrZpyomo.common.fileutilsrrrrrr+objectr rrrr s