From: Alan T. DeKok Date: Tue, 21 Nov 2023 19:55:39 +0000 (-0500) Subject: cache log level in log_dst_t and use it to skip logging destinations. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7f4242dd3f1bc7ae4e03a35f21a94850591d6d8;p=thirdparty%2Ffreeradius-server.git cache log level in log_dst_t and use it to skip logging destinations. The idea is that we can add a debug destination, where debug messages go. But normal messages still get passed through to *both* the debug destination, and to the normal destination. That we can add debug logging, and still have normal messages go to the normal log destination --- diff --git a/src/lib/server/log.c b/src/lib/server/log.c index 73861e8f9f3..cbe3ce13b81 100644 --- a/src/lib/server/log.c +++ b/src/lib/server/log.c @@ -618,13 +618,15 @@ void log_request(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt, ...) { va_list ap; - log_dst_t *dst_p; + log_dst_t *dst; if (!request->log.dst) return; va_start(ap, fmt); - for (dst_p = request->log.dst; dst_p; dst_p = dst_p->next) { - dst_p->func(type, lvl, request, file, line, fmt, ap, dst_p->uctx); + for (dst = request->log.dst; dst; dst = dst->next) { + if (lvl < dst->lvl) continue; + + dst->func(type, lvl, request, file, line, fmt, ap, dst->uctx); } va_end(ap); } diff --git a/src/lib/server/log.h b/src/lib/server/log.h index 7a645f60b14..82acdde6d98 100644 --- a/src/lib/server/log.h +++ b/src/lib/server/log.h @@ -65,6 +65,7 @@ typedef void (*log_func_t)(fr_log_type_t type, fr_log_lvl_t lvl, request_t *requ struct log_dst { log_func_t func; //!< Function to call to log to this destination. void *uctx; //!< Context to pass to the logging function. + fr_log_lvl_t lvl; //!< Log messages with lvl >= to this should be logged. log_dst_t *next; //!< Next logging destination. };