See more details about the Streams in the API

Customizable Streams

TBTK provides several output Streams that can be used to print diagnostic information etc. It is, of course, possible to use the C style printf() or C++ style std::cout for this. However, the TBTK Streams can be customized in ways that are useful for numerical calculations. Further, all information printed by TBTK is printed through these Streams. So even if printf() or std::out is used in application code, knowledge about these Streams is useful for tweaking the output of TBTK itself.

Streams::out, Streams::log, and Streams::err

The Streams interface has three output channels called Streams::out, Streams::log, and Streams::err. By default, Streams::out and Streams::err are mapped directly onto std::cout and std::cerr, respectively. These two Streams are also forked to Streams::log, which does nothing by default. What this means is that by default Streams::out and Streams::err works just like std::cout and std::cerr.

Opening and closing the log

It is possible to make Streams::log write to an output file by typing


In addition to directing the output of both Streams::out and Streams::err to the log file, this call will also write some diagnostic information. This includes a timestamp and the version number and git hash of the currently installed version of TBTK. This is information that ensures that the results can be reproduced in the future. Knowing the version number makes it possible to recompile an application in the future using the exact same version of TBTK. The git hash is there to make this possible even if a named release is not used.

A corresponding close call should be made before the application finishes to avoid losing any of the output.


This will also write a timestamp to the log before closing it.

Muting the output to std::cout and std::cerr

It is also possible to mute the output that is directed to std::cout and std::err as follows


This will not mute the output of Streams::out and Streams::err to the log. If the log is opened, the result is, therefore, that the output is directed to the log file alone. If the application code writes immediately to std::cout, this can be used to direct application-specific output to the terminal and TBTK output to the log file. We note, however, that it is recommended to not mute the output to cerr. Doing so can result in some error messages being lost at a crash.


Although not part of the Streams interface, many classes implement a Communicator interface. Instead of muting the Streams, it is possible to mute all such Communicators using


It is also possible to mute individual classes that implement the Communicator interface.


In contrast to muting the Streams, as described above, this will mute the component completely. A muted Communicator will, therefore, not even write to the log.

Next: Timer