summaryrefslogtreecommitdiffstats
path: root/bindings/python
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/python')
-rw-r--r--bindings/python/wrapper_bottom.c2
-rw-r--r--bindings/python/wrapper_top.c42
2 files changed, 44 insertions, 0 deletions
diff --git a/bindings/python/wrapper_bottom.c b/bindings/python/wrapper_bottom.c
index 51de44b0..a899188d 100644
--- a/bindings/python/wrapper_bottom.c
+++ b/bindings/python/wrapper_bottom.c
@@ -14,5 +14,7 @@ init_lasso(void)
Py_INCREF(&PyGObjectPtrType);
PyModule_AddObject(m, "PyGObjectPtr", (PyObject *)&PyGObjectPtrType);
+ lasso_log_set_handler(G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION | G_LOG_LEVEL_MASK,
+ lasso_python_log, NULL);
}
diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c
index 1934eaec..99f5fd9f 100644
--- a/bindings/python/wrapper_top.c
+++ b/bindings/python/wrapper_top.c
@@ -598,3 +598,45 @@ set_object_field(GObject **a_gobject_ptr, PyGObjectPtr *a_pygobject) {
*a_gobject_ptr = g_object_ref(a_pygobject->obj);
}
}
+
+static PyObject *_logger_object = NULL;
+
+static PyObject *get_logger_object() {
+ if (_logger_object == NULL) {
+ PyObject *logging_module = PyImport_ImportModule("logging");
+ _logger_object = PyObject_CallMethod(logging_module, "getLogger",
+ "s#", "lasso", sizeof("lasso")-1);
+ Py_DECREF(logging_module);
+ }
+ return _logger_object;
+}
+
+static void
+lasso_python_log(G_GNUC_UNUSED const char *domain, GLogLevelFlags log_level, const gchar *message,
+ G_GNUC_UNUSED gpointer user_data)
+{
+ PyObject *logger_object = get_logger_object();
+ char *method = NULL;
+
+ switch (log_level) {
+ case G_LOG_LEVEL_DEBUG:
+ method = "debug";
+ break;
+ case G_LOG_LEVEL_INFO:
+ case G_LOG_LEVEL_MESSAGE:
+ method = "info";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ method = "warning";
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ method = "error";
+ break;
+ case G_LOG_LEVEL_ERROR:
+ method = "critical";
+ break;
+ default:
+ return;
+ }
+ PyObject_CallMethod(logger_object, method, "s#s", "%s", 2, message);
+}