From: Michael Tremer Date: Wed, 27 Sep 2023 15:32:47 +0000 (+0000) Subject: libpakfire: Move loglevel into flags on create for Pakfire X-Git-Tag: 0.9.30~1625 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cdd2343847b92b83ffc60770ba2c9c6e83839a65;p=pakfire.git libpakfire: Move loglevel into flags on create for Pakfire Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 6a8dc55bf..1e7ea60d5 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -221,7 +221,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { goto ERROR; } - int flags = 0; + int flags = PAKFIRE_FLAGS_DEBUG; // Enable offline mode if (offline) @@ -235,7 +235,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { // Create a new Pakfire instance r = pakfire_create(&self->pakfire, path, arch, fconf, flags, - LOG_DEBUG, Pakfire_log_callback, self->callbacks.log); + Pakfire_log_callback, self->callbacks.log); Py_END_ALLOW_THREADS diff --git a/src/cli/pakfire/main.c b/src/cli/pakfire/main.c index 80e0db344..6d0048a3e 100644 --- a/src/cli/pakfire/main.c +++ b/src/cli/pakfire/main.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -48,7 +47,6 @@ struct config { char* arch; char* root; int flags; - int loglevel; int yes; // Repos @@ -163,7 +161,7 @@ static int parse_argv(struct config* config, int argc, char* argv[]) { break; case ARG_DEBUG: - config->loglevel = LOG_DEBUG; + config->flags |= PAKFIRE_FLAGS_DEBUG; break; case ARG_OFFLINE: @@ -228,7 +226,6 @@ int main(int argc, char* argv[]) { .arch = NULL, .root = "/", .flags = 0, - .loglevel = LOG_INFO, .yes = 0, }; @@ -247,7 +244,7 @@ int main(int argc, char* argv[]) { // Initialize Pakfire r = pakfire_create(&pakfire, config.root, config.arch, f, - config.flags, config.loglevel, NULL, NULL); + config.flags, NULL, NULL); if (r) goto ERROR; diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 975d9eba9..9154cee4a 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -38,7 +38,8 @@ struct pakfire; #include enum pakfire_flags { - PAKFIRE_FLAGS_OFFLINE = (1 << 0), + PAKFIRE_FLAGS_DEBUG = (1 << 0), + PAKFIRE_FLAGS_OFFLINE = (1 << 1), }; // Callbacks @@ -54,7 +55,7 @@ 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, - FILE* conf, int flags, int loglevel, pakfire_log_callback log_callback, void* log_data); + FILE* conf, int flags, 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 a1a4d203e..45d725011 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -892,8 +892,7 @@ ERROR: } PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, - const char* arch, FILE* conf, int flags, - int loglevel, pakfire_log_callback log_callback, void* log_data) { + const char* arch, FILE* conf, int flags, pakfire_log_callback log_callback, void* log_data) { char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX"; char private_dir[PATH_MAX]; int r = 1; @@ -918,9 +917,11 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, else pakfire_set_log_callback(p, pakfire_log_syslog, NULL); - // Set log level - if (loglevel) { - pakfire_log_set_priority(p, loglevel); + // Set log level to debug if in debug mode + if (pakfire_has_flag(p, PAKFIRE_FLAGS_DEBUG)) { + pakfire_log_set_priority(p, LOG_DEBUG); + + // Otherwise take the log level from the environment } else { const char* env = secure_getenv("PAKFIRE_LOG"); if (env) diff --git a/tests/parser/test.c b/tests/parser/test.c index 9e83f30c3..36b61679f 100644 --- a/tests/parser/test.c +++ b/tests/parser/test.c @@ -44,7 +44,7 @@ int main(int argc, const char* argv[]) { // Create a pakfire instance r = pakfire_create(&pakfire, root, NULL, NULL, - 0, LOG_DEBUG, pakfire_log_stderr, NULL); + PAKFIRE_FLAGS_DEBUG, pakfire_log_stderr, NULL); if (r) { fprintf(stderr, "Could not create Pakfire: %m\n"); goto ERROR; diff --git a/tests/testsuite.c b/tests/testsuite.c index 06714d4ed..398099575 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -36,6 +36,7 @@ struct testsuite ts; static int test_run(int i, struct test* t) { struct pakfire* p = NULL; FILE* c = NULL; + const int flags = PAKFIRE_FLAGS_DEBUG; char root[PATH_MAX] = TEST_ROOTFS "/pakfire-test-XXXXXX"; int r; @@ -58,7 +59,7 @@ static int test_run(int i, struct test* t) { } // Create a pakfire instance - r = pakfire_create(&t->pakfire, root, NULL, c, 0, LOG_DEBUG, pakfire_log_stderr, NULL); + r = pakfire_create(&t->pakfire, root, NULL, c, flags, pakfire_log_stderr, NULL); if (r) { LOG("ERROR: Could not initialize pakfire: %m\n"); goto ERROR;