New feature: Python console displays more log messages

Until now, the Python console only displayed Python outputs and Python log messages. Therefore, if a Python command executed a VTK method and that VTK method logged an error or warning, it was not immediately visible for the developer (the developer had to notice the change in the log icon, click on it, and scroll down to see the new message).

In latest Slicer Preview Release (Slicer 5.1.0-2022-10-15 and later), the Python console displays log messages from all sources - Python, Qt, VTK, ITK.

For example:

Old behavior (return value indicates error but no hint on what went wrong):

New behavior:

If the extra messages are not desirable (e.g., because they cause too much distraction for a developer) then the log level can be adjusted in Application Settings β†’ Python β†’ Log level. Default log level is Warning, which means that warnings and error log messages are displayed. Set level to None to prevent displaying any log messages (as it was before). Set level to Debug to show all available messages.

5 Likes

It’s great to see log messages from VTK in the python console as you show in your images above!

@lassoan Is this change supposed to impact the functionality that is the Slicer_BUILD_WIN32_CONSOLE_LAUNCHER option with local Slicer builds? With that option on Windows we would see a console window open in addition to the Slicer main window and that would contain all the logging output from python, Qt, VTK, ITK sources. Currently with the latest Slicer preview, modules that have any python logging do not display these messages to the Win32 console window. These python logging messages are only seen when viewing the actual log file or in the python console (of course as long as the message is within the Application Settings->Python->Log level).

Previously, Slicer relied on standard output for Python logging (the Python logger printed on the standard output and the application logger captured that output). This was too restrictive (it was not possible to make log messages appear in the Python console without appearing twice in the application log). Now they are independently configurable and so the previous limitations are gone.

If you want Python logs to be printed on the process output then you can register a Python log handler to do that, the same way as you would do in any other Python environment.

1 Like

With these latest changes, is there any value to still have Slicer_BUILD_WIN32_CONSOLE_LAUNCHER as a a default build option if building Python support is a default option which supports viewing all the output on the python console? I’m thinking about some new python Slicer developers that may get confused about where to look for logging output.

For typing Python commands or debugging Python code I would recommend using the Python console.

For checking what happened in the application, the application log viewer has the slight advantages (filtering, grouping, and clearing) compared to the Python console.

For reporting errors, the Help/Report a bug has some advantages (easier to copy all messages, previous sessions are available).

The only use that I see for the process output is when there is no application GUI.