From 67537d79eda6ce4e5765b7ebf548be4a3946760d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 22 Sep 2016 22:55:47 +0200 Subject: [PATCH] python/ext/aubiomodule.c: use custom logging function for errors and warnings --- python/ext/aubiomodule.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/python/ext/aubiomodule.c b/python/ext/aubiomodule.c index d3f03610..616dc759 100644 --- a/python/ext/aubiomodule.c +++ b/python/ext/aubiomodule.c @@ -256,6 +256,22 @@ static struct PyModuleDef moduledef = { }; #endif +void +aubio_log_function(int level, const char *message, void *data) +{ + // remove trailing \n + char *pos; + if ((pos=strchr(message, '\n')) != NULL) { + *pos = '\0'; + } + // warning or error + if (level == AUBIO_LOG_ERR) { + PyErr_Format(PyExc_RuntimeError, "%s", message); + } else { + PyErr_WarnEx(PyExc_UserWarning, message, 1); + } +} + static PyObject * initaubio (void) { @@ -315,6 +331,8 @@ initaubio (void) // add ufunc add_ufuncs(m); + aubio_log_set_level_function(AUBIO_LOG_ERR, aubio_log_function, NULL); + aubio_log_set_level_function(AUBIO_LOG_WRN, aubio_log_function, NULL); return m; } -- 2.11.0