From: Michael Tremer Date: Fri, 14 Feb 2025 17:47:05 +0000 (+0000) Subject: log file: Never write any debug stuff to the file X-Git-Tag: 0.9.30~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe878bea2b7857c7b402334fc2e41c131678f843;p=pakfire.git log file: Never write any debug stuff to the file Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/build.c b/src/cli/lib/build.c index 02ce7c78..beb129a9 100644 --- a/src/cli/lib/build.c +++ b/src/cli/lib/build.c @@ -156,7 +156,7 @@ static void log_callback(void* data, int priority, const char* file, int line, // Write to the log file if (local_args->log_file) - pakfire_log_file_write(local_args->log_file, buffer, length); + pakfire_log_file_write(local_args->log_file, priority, buffer, length); if (buffer) free(buffer); diff --git a/src/pakfire/job.c b/src/pakfire/job.c index a6374ae5..340f9c73 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -600,16 +600,8 @@ static void pakfire_job_log(void* data, int priority, const char* file, } // Send everything but debug messages to the log file - if (likely(job->log.file)) { - switch (priority) { - case LOG_DEBUG: - break; - - default: - pakfire_log_file_write(job->log.file, buffer, length); - break; - } - } + if (likely(job->log.file)) + pakfire_log_file_write(job->log.file, priority, buffer, length); // Pass everything to the upstream logger pakfire_ctx_log_condition(job->ctx, priority, "%s", buffer); diff --git a/src/pakfire/log_file.c b/src/pakfire/log_file.c index 7a37a075..4cdbcf09 100644 --- a/src/pakfire/log_file.c +++ b/src/pakfire/log_file.c @@ -188,7 +188,7 @@ int pakfire_log_file_close(struct pakfire_log_file* self) { return 0; } -int pakfire_log_file_write(struct pakfire_log_file* self, const char* buffer, ssize_t length) { +int pakfire_log_file_write(struct pakfire_log_file* self, int priority, const char* buffer, ssize_t length) { int r; // Check inputs @@ -199,6 +199,15 @@ int pakfire_log_file_write(struct pakfire_log_file* self, const char* buffer, ss if (unlikely(!self->f)) return -EBADF; + // Don't log any debugging stuff to the file + switch (priority) { + case LOG_DEBUG: + return 0; + + default: + break; + } + // Automatically determine the length if (unlikely(length < 0)) length = strlen(buffer); diff --git a/src/pakfire/log_file.h b/src/pakfire/log_file.h index 584cfcd3..2de23387 100644 --- a/src/pakfire/log_file.h +++ b/src/pakfire/log_file.h @@ -43,6 +43,7 @@ const char* pakfire_log_file_path(struct pakfire_log_file* self); int pakfire_log_file_close(struct pakfire_log_file* self); -int pakfire_log_file_write(struct pakfire_log_file* self, const char* buffer, ssize_t length); +int pakfire_log_file_write(struct pakfire_log_file* self, + int priority, const char* buffer, ssize_t length); #endif /* PAKFIRE_LOG_FILE_H */ diff --git a/tests/libpakfire/log_file.c b/tests/libpakfire/log_file.c index 845effed..baebaff2 100644 --- a/tests/libpakfire/log_file.c +++ b/tests/libpakfire/log_file.c @@ -38,7 +38,7 @@ static int __test_simple(const struct test* t, int flags) { // Write something to the file for (int i = 0; i < 10; i++) - ASSERT_SUCCESS(pakfire_log_file_write(file, "BUFFER DATA\n", -1)); + ASSERT_SUCCESS(pakfire_log_file_write(file, LOG_INFO, "BUFFER DATA\n", -1)); // Everything passed r = EXIT_SUCCESS;