ID 606542 - Python logging always prints to Nuke's console in GUI and Terminal mode

Follow

Problem summary
Python logging always prints to Nuke's console in GUI and Terminal mode.
This does not happen when using Nuke's Python interpreter.
 
Customer reported version
Nuke 15.1v2
 
Customer reported platform
Rocky 8
 
Steps to reproduce
 
1) Open Nuke.
 
2) Run the following code in the Script Editor.

import logginglogger = logging.getLogger(__name__)logger.setLevel(logging.DEBUG)console_handler = logging.FileHandler("/tmp/file_handler_test.txt") formatter_stdout = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")console_handler.setFormatter(formatter_stdout)logger.addHandler(console_handler)logger.debug("debug message")logger.info("info message")
 
NOTE: You will need to ensure that the file is written to a valid location on this line:
console_handler = logging.FileHandler("/tmp/file_handler_test.txt") 
 
Expected behaviour
The logging messages should only be printed to the external file.
 
Actual behaviour
The logging messages are also returned in Nuke's console/terminal window.
 
Workaround
 
In this case, you can set logger.propagate = False. For example:
import logging logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) console_handler = logging.FileHandler("/tmp/file_handler_test.txt") formatter_stdout = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") console_handler.setFormatter(formatter_stdout) logger.addHandler(console_handler) logger.propagate = False logger.debug("debug message") logger.info("info message")
 
Reproduced by support
This bug has been reproduced in:
Nuke 16.0v5 - Windows 11 - macOS 15 (Sequoia)
Nuke 12.0v1 - Windows 11 - macOS 15 (Sequoia)
 
Earliest version tested
Nuke 12.0v1
- This issue appears to be in all tested versions of the product
 

    We're sorry to hear that

    Please tell us why