From: Paul Brossier Date: Thu, 22 Sep 2016 20:55:47 +0000 (+0200) Subject: python/ext/aubiomodule.c: use custom logging function for errors and warnings X-Git-Tag: 0.4.4~206 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=67537d79eda6ce4e5765b7ebf548be4a3946760d;p=aubio.git python/ext/aubiomodule.c: use custom logging function for errors and warnings --- 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; }