#NEWLINE# @ contextlib . contextmanager #NEWLINE# def intercept_log_messages( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mylog = logging . getLogger ( 'nova' ) #NEWLINE# stream = cStringIO ( ) #NEWLINE# handler = logging . logging . StreamHandler ( stream ) #NEWLINE# handler . setFormatter ( formatters . ContextFormatter ( ) ) #NEWLINE# mylog . logger . addHandler ( stream ) #NEWLINE# ( yield stream ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# mylog . logger . removeHandler ( handler )