From f29293ffdde2046c0fc43bc566ccb16bc33fcf65 Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Wed, 15 Jan 2025 12:34:59 -0600 Subject: [PATCH] Avoid duplicate log entries (#6222) Previously the logger would have two sinks configured (the default + our custom one). This PR clears the default logger before registering our custom one. Authors: - Jim Crist-Harif (https://github.com/jcrist) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) URL: https://github.com/rapidsai/cuml/pull/6222 --- 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))