# Output Widget¶

Stdout and stderr are normally directed to appear in the output of the cell whose code produced them. The output widget allows you to consolidate output in one place, both captured IO and rich objects.

This can be used for logging and also for catching the output of background threads, which can be left running after the cell that starts them completes.

The widget can be configured to capture just stdout or just stderr.

## Example¶

First we create the Output. Initially there is nothing in it, the Output is empty and so nothing appears.

In [ ]:
%import com.twosigma.beakerx.widget.Output
out = new Output()
OutputManager.setOutput(out)
out


The next cell starts a background thread that writes into that output. The results appear above, in the output.

In [ ]:
t = new Thread({
for (int i = 0; i <20 ; i++){
if (i % 5 == 3) System.err.println("stderr!")
if (i % 6 == 2) out.display(HTML('any <b>MIME</b> <em>type</em>'))
if (i % 7 == 4) out.display(new Plot(initHeight:150) << new Line(y: [0,5,2,3,11]))
}});
t.start()


Run the following cells after starting the threads with the previous cell.

In [ ]:
println("some other cell")

In [ ]:
OutputManager.clearOutput()

In [ ]:
OutputManager.setOutput(null)

In [ ]:
t.stop()


## Only StdOut¶

In [ ]:
onlyOut = new Output()
OutputManager.setStdout(onlyOut)
onlyOut

In [ ]:
println("only stdout is captured")
System.err.println("stderr goes to its own cell")

In [ ]:
OutputManager.clear()
OutputManager.setStdout(null)


## Only Stderr¶

In [ ]:
onlyErr = new Output()
OutputManager.setStderr(onlyErr)
onlyErr

In [ ]:
println("only stdout is captured")
System.err.println("stderr goes to its own cell")

In [ ]:
OutputManager.clear()
OutputManager.setStderr(null)