From: Michael Tremer Date: Sun, 17 Jul 2022 17:26:43 +0000 (+0000) Subject: pakfire: Pass loglevel on creation X-Git-Tag: 0.9.28~697 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcb98c7baf95c5d9fd02c524b0515f8bb4b2a27f;p=pakfire.git pakfire: Pass loglevel on creation Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 71f775c9f..b9b3eb3be 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -199,7 +199,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { // Create a new Pakfire instance int r = pakfire_create(&self->pakfire, path, arch, conf, flags, - Pakfire_log_callback, self->callbacks.log); + LOG_DEBUG, Pakfire_log_callback, self->callbacks.log); if (r) { switch (errno) { // Invalid architecture or path diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index c971c49e2..392a87819 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -64,7 +64,8 @@ typedef void (*pakfire_status_callback)(struct pakfire* pakfire, void* data, int progress, const char* status); int pakfire_create(struct pakfire** pakfire, const char* path, const char* arch, - const char* conf, int flags, pakfire_log_callback log_callback, void* log_data); + const char* conf, int flags, + int loglevel, pakfire_log_callback log_callback, void* log_data); struct pakfire* pakfire_ref(struct pakfire* pakfire); struct pakfire* pakfire_unref(struct pakfire* pakfire); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 3cd962fee..9d3dd50e8 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -697,7 +697,7 @@ ERROR: PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, const char* arch, const char* conf, int flags, - pakfire_log_callback log_callback, void* log_data) { + int loglevel, pakfire_log_callback log_callback, void* log_data) { char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/XXXXXX"; int r = 1; @@ -743,9 +743,14 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, else pakfire_set_log_callback(p, pakfire_log_syslog, NULL); - const char* env = secure_getenv("PAKFIRE_LOG"); - if (env) - pakfire_log_set_priority(p, log_priority(env)); + // Set log level + if (loglevel) { + pakfire_log_set_priority(p, loglevel); + } else { + const char* env = secure_getenv("PAKFIRE_LOG"); + if (env) + pakfire_log_set_priority(p, log_priority(env)); + } // Setup confirm callback pakfire_set_confirm_callback(p, pakfire_ui_confirm, NULL); diff --git a/tests/testsuite.c b/tests/testsuite.c index 82bfb8beb..5da2cef99 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -48,15 +48,12 @@ static int test_run(int i, struct test* t) { // Create a pakfire instance r = pakfire_create(&t->pakfire, root, NULL, TEST_SRC_PATH "/pakfire.conf", - 0, pakfire_log_stderr, NULL); + 0, LOG_DEBUG, pakfire_log_stderr, NULL); if (r) { LOG("ERROR: Could not initialize pakfire: %m\n"); exit(1); } - // Enable debug logging - pakfire_log_set_priority(t->pakfire, LOG_DEBUG); - r = t->func(t); if (r) LOG("Test failed with error code: %d\n", r);