From 70a1b752c9930beb5bdc7f7c07f8cc9b94333c56 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 1 Mar 2021 13:30:02 -0500 Subject: [PATCH] chelper: Move logging_callback() to global scope Signed-off-by: Kevin O'Connor --- klippy/chelper/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index 851fda70..76d5c4b4 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -218,6 +218,10 @@ FFI_main = None FFI_lib = None pyhelper_logging_callback = None +# Hepler invoked from C errorf() code to log errors +def logging_callback(msg): + logging.error(FFI_main.string(msg)) + # Return the Foreign Function Interface api to the caller def get_ffi(): global FFI_main, FFI_lib, pyhelper_logging_callback @@ -238,10 +242,8 @@ def get_ffi(): FFI_main.cdef(d) FFI_lib = FFI_main.dlopen(destlib) # Setup error logging - def logging_callback(msg): - logging.error(FFI_main.string(msg)) - pyhelper_logging_callback = FFI_main.callback( - "void func(const char *)", logging_callback) + pyhelper_logging_callback = FFI_main.callback("void func(const char *)", + logging_callback) FFI_lib.set_python_logging_callback(pyhelper_logging_callback) return FFI_main, FFI_lib