aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/chelper.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-30 12:04:28 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-30 21:19:43 -0500
commit4f07ee4d92732d0b619553d366b50b4b758c3d87 (patch)
treee4bf83d205001cafba04725aa6b1da9254620575 /klippy/chelper.py
parentb14db404b55424ef783a163a02da8868120b36c9 (diff)
downloadkutter-4f07ee4d92732d0b619553d366b50b4b758c3d87.tar.gz
kutter-4f07ee4d92732d0b619553d366b50b4b758c3d87.tar.xz
kutter-4f07ee4d92732d0b619553d366b50b4b758c3d87.zip
pyhelper: Add ability to route error messages to python logging
Instead of writing error messages to stderr, route them into the python code and use the standard python logging system. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/chelper.py')
-rw-r--r--klippy/chelper.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/klippy/chelper.py b/klippy/chelper.py
index 7fb8fd98..58049582 100644
--- a/klippy/chelper.py
+++ b/klippy/chelper.py
@@ -71,6 +71,10 @@ defs_serialqueue = """
, struct pull_queue_message *q, int max);
"""
+defs_pyhelper = """
+ void set_python_logging_callback(void (*func)(const char *));
+"""
+
# Return the list of file modification times
def get_mtimes(srcdir, filelist):
out = []
@@ -95,15 +99,23 @@ def check_build_code(srcdir):
FFI_main = None
FFI_lib = None
+pyhelper_logging_callback = None
# Return the Foreign Function Interface api to the caller
def get_ffi():
- global FFI_main, FFI_lib
+ global FFI_main, FFI_lib, pyhelper_logging_callback
if FFI_lib is None:
srcdir = os.path.dirname(os.path.realpath(__file__))
check_build_code(srcdir)
FFI_main = cffi.FFI()
FFI_main.cdef(defs_stepcompress)
FFI_main.cdef(defs_serialqueue)
+ FFI_main.cdef(defs_pyhelper)
FFI_lib = FFI_main.dlopen(os.path.join(srcdir, DEST_LIB))
+ # Setup error logging
+ def logging_callback(msg):
+ logging.error(FFI_main.string(msg))
+ pyhelper_logging_callback = FFI_main.callback(
+ "void(const char *)", logging_callback)
+ FFI_lib.set_python_logging_callback(pyhelper_logging_callback)
return FFI_main, FFI_lib