From 700cdf409031758cbf9c468119e8611a4f9f1557 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 26 Feb 2026 21:55:01 +0100 Subject: [PATCH] Message handlers are no longer cleared --- .../src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp b/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp index 2c663607..26459146 100644 --- a/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp +++ b/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp @@ -154,8 +154,14 @@ PYBIND11_MODULE(SofaRuntime, m) { }, "automatically load plugins from configuration files"); m.def("init", []() { - MessageDispatcher::clearHandlers(); + + // Replaces MainConsoleMessageHandler by MainPythonMessageHandler: + // - MainConsoleMessageHandler prints messages in std::cout/std::cerr. + // - MainPythonMessageHandler prints the messages in the sys.stdout + // Keeping them both would result in duplicate messages in the console. + MessageDispatcher::rmHandler(&sofa::helper::logging::MainConsoleMessageHandler::getInstance()); MessageDispatcher::addHandler(&MainPythonMessageHandler::getInstance()); + MessageDispatcher::addHandler(&MainPerComponentLoggingMessageHandler::getInstance()); }, "redirect SOFA messages to Python's sys.stdout");