From: Michael Tremer Date: Thu, 25 Jan 2024 16:41:11 +0000 (+0000) Subject: python: ctx: Setup the default logger X-Git-Tag: 0.9.30~1248 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95ccfdc465aeab9e1e65982b81fee179a559f96b;p=pakfire.git python: ctx: Setup the default logger There was some code that started implementing this, but weirdly it was never called... Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/ctx.c b/src/_pakfire/ctx.c index e8fd927bf..e6729be4d 100644 --- a/src/_pakfire/ctx.c +++ b/src/_pakfire/ctx.c @@ -119,10 +119,11 @@ static void Ctx___set_logger(CtxObject* self, PyObject* logger) { // Store the new logger self->logger = logger; - Py_INCREF(self->logger); + Py_XINCREF(self->logger); // Set the logger - pakfire_ctx_set_log_callback(self->ctx, Ctx_log_callback, self->logger); + if (self->ctx) + pakfire_ctx_set_log_callback(self->ctx, Ctx_log_callback, self->logger); } static int Ctx_setup_logging(CtxObject* self) { @@ -143,6 +144,9 @@ static int Ctx_setup_logging(CtxObject* self) { // Set default logger Ctx___set_logger(self, logger); + // Success + r = 0; + ERROR: Py_XDECREF(logging); Py_XDECREF(logger); @@ -171,15 +175,21 @@ static int Ctx_init(CtxObject* self, PyObject* args, PyObject* kwargs) { // Set the log level to DEBUG pakfire_ctx_set_log_level(self->ctx, LOG_DEBUG); + // Setup the default logger + r = Ctx_setup_logging(self); + if (r) + return r; + return 0; } static void Ctx_dealloc(CtxObject* self) { + // Reset the logger + Ctx___set_logger(self, NULL); + if (self->ctx) pakfire_ctx_unref(self->ctx); - Py_XDECREF(self->logger); - Py_TYPE(self)->tp_free((PyObject *)self); } @@ -191,8 +201,6 @@ static PyObject* Ctx_set_logger(CtxObject* self, PyObject* args) { if (!PyArg_ParseTuple(args, "O", &logger)) return NULL; - // XXX Check if we have a log method - // Set the logger Ctx___set_logger(self, logger);