Inheritance diagram for IPython.OutputTrap:
Class to trap stdout and stderr and log them separately.
Class to trap standard output and standard error. They get logged in StringIO objects which are available as <instance>.out and <instance>.err. The class also offers summary methods which format this data a bit.
A word of caution: because it blocks messages, using this class can make debugging very tricky. If you are having bizarre problems silently, try turning your output traps off for a while. You can call the constructor with the parameter debug=1 for these cases. This turns actual trapping off, but you can keep the rest of your code unchanged (this has already been a life saver).
Example:
# config: trapper with a line of dots as log separator (final ‘n’ needed) config = OutputTrap(‘Config’,’Out ‘,’Err ‘,’.’*80+’n’)
# start trapping output config.trap_all()
# now all output is logged ... # do stuff...
# output back to normal: config.release_all()
# print all that got logged: print config.summary()
# print individual raw data: print config.out.getvalue() print config.err.getvalue()
Release both stdout and stderr.
Cacthes and discards OutputTrapError exceptions raised.
Release both stdout and stderr.
Cacthes and discards OutputTrapError exceptions raised.
Trap and log both stdout and stderr.
Cacthes and discards OutputTrapError exceptions raised.
Trap and log both stdout and stderr.
Cacthes and discards OutputTrapError exceptions raised.