]> git.ipfire.org Git - zone-sync.git/commitdiff
main: Setup logging from the libraries
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 12:40:10 +0000 (12:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 12:40:10 +0000 (12:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
main.c

diff --git a/main.c b/main.c
index e9eafbfb6bcf9a91b6c173f66755b62a22935c04..b3120b9d894e77978dd7559d99f94b53dcf09ea5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -24,6 +24,7 @@
 
 #include <urcu/wfcqueue.h>
 
+#include <isc/log.h>
 #include <isc/loop.h>
 #include <isc/mem.h>
 #include <isc/netmgr.h>
@@ -43,6 +44,9 @@ typedef struct ctx {
        // Memory Context
        isc_mem_t* memctx;
 
+       // Logging
+       isc_log_t* log;
+
        // Loop Manager
        isc_loopmgr_t* loopmgr;
 
@@ -90,9 +94,49 @@ static void logger(int priority, const char* format, ...) {
 }
 
 // Logging functions
-#define INFO(ctx, ...) logger(ctx, LOG_INFO, __VA_ARGS__)
-#define ERROR(ctx, ...) logger(ctx, LOG_ERR, __VA_ARGS__)
-#define DEBUG(ctx, ...) logger(ctx, LOG_DEBUG, __VA_ARGS__)
+#define INFO(...) logger(LOG_INFO, __VA_ARGS__)
+#define ERROR(...) logger(LOG_ERR, __VA_ARGS__)
+#define DEBUG(...) logger(LOG_DEBUG, __VA_ARGS__)
+
+static void setup_logging(void) {
+       isc_logconfig_t *logcfg = NULL;
+
+       /* Create the log context and a default config */
+       isc_log_create(ctx.memctx, &ctx.log, &logcfg);
+
+       /* Crank up debug verbosity */
+       isc_log_setdebuglevel(ctx.log, 99);
+
+       /* Define a channel that writes everything to stderr */
+       isc_logdestination_t dest = {
+               .file = {
+                       .stream = stderr,
+                       .name = NULL,
+                       .versions = 0,
+                       .maximum_size = 0,
+               },
+       };
+       isc_log_createchannel(
+               logcfg,
+               "stderr",                       /* channel name */
+               ISC_LOG_TOFILEDESC,             /* destination type */
+               ISC_LOG_DYNAMIC,                /* level — DYNAMIC follows setdebuglevel */
+               &dest,
+               ISC_LOG_PRINTTIME | ISC_LOG_PRINTLEVEL |
+               ISC_LOG_PRINTCATEGORY | ISC_LOG_PRINTMODULE);
+
+       /* Attach the channel to ALL categories/modules
+       * (NULL category = wildcard, NULL module = wildcard) */
+       isc_log_usechannel(logcfg, "stderr", NULL, NULL);
+
+       /* Tell libdns to register its categories/modules
+       * with this log context, and use it as default */
+       dns_log_init(ctx.log);
+       dns_log_setcontext(ctx.log);
+
+       /* Also make libisc itself use it */
+       isc_log_setcontext(ctx.log);
+}
 
 static void do_zone(ctx_t* ctx, const char* name) {
        DEBUG(ctx, "Processing zone %s\n", name);
@@ -189,6 +233,9 @@ int main(int argc, char* argv[]) {
        // Allocate a new memory context
        isc_mem_create(&ctx.memctx);
 
+       // Setup logging
+       setup_logging();
+
        // Initialize the loop manager
        isc_loopmgr_create(ctx.memctx, 1, &ctx.loopmgr);