From 71dc1cfd08d55e9869a9b5adafd19a59da7526d4 Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Mon, 13 Jan 2025 17:12:43 -0600 Subject: [PATCH] Avoid duplicate log entries Previously the logger would have two sinks configured (the default + our custom one). This PR clears the default logger before registering our custom one. --- python/cuml/cuml/internals/logger.pxd | 1 + python/cuml/cuml/internals/logger.pyx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/python/cuml/cuml/internals/logger.pxd b/python/cuml/cuml/internals/logger.pxd index 6556cb0505..d39c7d24df 100644 --- a/python/cuml/cuml/internals/logger.pxd +++ b/python/cuml/cuml/internals/logger.pxd @@ -47,6 +47,7 @@ IF GPUBUILD == 1: cdef cppclass sink_vector: void push_back(const sink_ptr& sink) except + void pop_back() except + + void clear() cdef extern from "cuml/common/logger.hpp" namespace "ML" nogil: cdef cppclass logger: diff --git a/python/cuml/cuml/internals/logger.pyx b/python/cuml/cuml/internals/logger.pyx index 0bc09126bd..5dec86fd18 100644 --- a/python/cuml/cuml/internals/logger.pyx +++ b/python/cuml/cuml/internals/logger.pyx @@ -319,5 +319,6 @@ def flush(): IF GPUBUILD == 1: - # Set callback functions to handle redirected sys.stdout in Python + # Clear existing sinks and add a callback sink to redirect to sys.stdout + default_logger().sinks().clear() default_logger().sinks().push_back( make_shared[callback_sink_mt](_log_callback, _log_flush))