How can I redirect std::cout to Python Interactor?

I’m developing a C++ extension and there are lots of output messages using “std::cout”.

However, I can only see these messages when slicer started from terminal and cannot see them in the python interactor.

How can I redirect those messages to python interactor?

Did you also consider looking at the Error Log ?

See https://slicer.readthedocs.io/en/latest/user_guide/user_interface.html#application-menu

This should list all messages.

1 Like

If you develop the extension then I assume you have control over the logging. In this case I’d suggest using VTK or Qt macros for logging (depending on whether your class is VTK or Qt based). I’m thinking about vtk[Debug/Info/Warning/Error]Macro and qDebug/qWarning/qCritical. These will appear in the Python console. Be mindful that you may need to lower the log level in Application Settings if you want to use vtkInfoMacro for example.

1 Like