From: Michael Tremer Date: Mon, 11 May 2026 12:40:10 +0000 (+0000) Subject: main: Setup logging from the libraries X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=29f00ece18ea070353837ae2ad967a1b91cdba5f;p=zone-sync.git main: Setup logging from the libraries Signed-off-by: Michael Tremer --- diff --git a/main.c b/main.c index e9eafbf..b3120b9 100644 --- a/main.c +++ b/main.c @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -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);