B u `"@sddlZddlZddlZddlZddlmZedZedZGdddej Z e dZ e e edd d e ejGd d d eZdS) N)PYOMO_ROOT_DIRz\s*z^\[\s*[A-Za-z0-9\.]+\s*\]c@s(eZdZddejdfddZddZdS) LogHandlerNcCsVtjj||d|dkr dd}|dkr.tj}||_||_||_d|_d|_ d|_ dS)N)levelcSsdS)NTrrr4/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/common/log.py'z%LogHandler.__init__..Nrz ) loggingHandler__init__sysstdout verbositystreambasepathwrapinitial_indentsubsequent_indent)selfbaserrrrrrr "szLogHandler.__init__c Cs|j}|}t|}g}t|}g}x|D]}t|}|} | sn| ||fg}d}q8||krt | dkr|r| ddkr| ddks| ddkrt | r| ||fg}| | q8| ||f| g}|}q8W|r| ||fx"|r$|dds$| qWx$|rJ|ddsJ| dq(W| r|j} |j} y |j} Wntk rd} YnX|jr| |jrd| t |jd} |jd || | | fn\|rd| dd} |rd || f} n|} |jd tj| |j|j|jd fx|D]\}}|sFd }|rvt |ddkrv|dddkrvd}nd }|jd tjd||j|j||j||d fq4WdS)N rz-* [z (unknown)z[base]z%s: "%s", %d, %s z%s: %sz%s )widthrrrz-*z ) levelname getMessagetextwrapdedent _indentionmatchgroup splitlinesstripappendlen _status_repoprpathnamelinenofuncNameAttributeErrorr startswithrwritejoinfillrrr)rrecordrmsgZ paragraphsindentZ par_lineslineleadingcontentfilenamer+functionZfirstParparZhangrrremit3s~     *zLogHandler.emit)__name__ __module__ __qualname__r NOTSETr r;rrrrr srZpyomocCs ttjS)N)_logger isEnabledForr DEBUGrrrrrr r)rc@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)routputrIrrrrr s   zLoggingIntercept.__init__cCsHt|j}|j|j|jf|_g|_d|_||jj| |jdS)Nr) r getLoggerrIr propagatehandlersrJrHrE addHandler)rloggerrrr __enter__s  zLoggingIntercept.__enter__cCsXt|j}||j||jd|jd|_x|jdD]}|j |q@WdS)Nrr) r rLrI removeHandlerrErHrJrMrNr&)retZevtbrPhrrr__exit__s    zLoggingIntercept.__exit__) r<r=r>__doc__r WARNINGr rQrWrrrrrCsrC)r rerrZpyomo.common.fileutilsrcompiler!r(r rrLr@rOrHrYobjectrCrrrrs