#include "lib/defines.h"
#include "lib/utils.h"
-#ifndef NOVERBOSELOG
- /** @internal Print a debug message related to resolution. */
- #define QRVERBOSE(query, cls, ...) { \
- const struct kr_query *q = (query); \
- if (kr_log_trace_enabled(q)) { \
- kr_log_trace(q, cls, __VA_ARGS__); \
- } else if (VERBOSE_STATUS) { \
- unsigned _ind = 0; \
- uint32_t _q_uid = q ? q->uid : 0; \
- uint32_t _req_uid = q && q->request ? q->request->uid : 0; \
- for (; q; q = q->parent, _ind += 2); \
- /* simplified kr_log_verbose() calls */ \
- printf("[%05u.%02u][%s] %*s", _req_uid, _q_uid, cls, _ind, ""); \
- printf(__VA_ARGS__); \
- fflush(stdout); \
- } \
-}
+#ifdef NOVERBOSELOG
+ #define QRVERBOSE(query, cls, ...)
#else
- #define QRVERBOSE(query, cls, ...)
+ /** Print a debug message related to resolution.
+ * \param _query associated kr_query, may be NULL
+ * \param _cls identifying string, typically of length exactly four (padded)
+ * \param ... printf-compatible list of parameters
+ */
+ #define QRVERBOSE(_query, _cls, ...) do { \
+ const struct kr_query *_qry = (_query); \
+ if (kr_log_trace_enabled(_qry)) { \
+ kr_log_trace(_qry, (_cls), __VA_ARGS__); \
+ } else if (VERBOSE_STATUS) { \
+ kr_log_qverbose_impl(_qry, (_cls), __VA_ARGS__); \
+ } \
+ } while (false)
#endif
/** Layer processing states. Only one value at a time (but see TODO).
const knot_pktsection_t *ans = knot_pkt_section(pkt, KNOT_ANSWER);
if ((pkt_class & (PKT_NOERROR)) && ans->count > 0 &&
knot_dname_is_equal(pkt_qname, query->zone_cut.name)) {
- VERBOSE_MSG("<= continuing with qname minimization\n")
+ VERBOSE_MSG("<= continuing with qname minimization\n");
} else {
/* fall back to disabling minimization */
VERBOSE_MSG("<= retrying with non-minimized name\n");
}
}
+void kr_log_qverbose_impl(const struct kr_query *qry, const char *cls, const char *fmt, ...)
+{
+ unsigned ind = 0;
+ for (const struct kr_query *q = qry; q; q = q->parent)
+ ind += 2;
+ uint32_t qry_uid = qry ? qry->uid : 0;
+ uint32_t req_uid = qry && qry->request ? qry->request->uid : 0;
+ /* Simplified kr_log_verbose() calls, first prefix then passed fmt...
+ * Calling it would take about the same amount of code. */
+ printf("[%05u.%02u][%s] %*s", req_uid, qry_uid, cls, ind, "");
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+ fflush(stdout);
+}
+
bool kr_log_trace(const struct kr_query *query, const char *source, const char *fmt, ...)
{
if (!kr_log_trace_enabled(query)) {
KR_EXPORT KR_PRINTF(1)
void kr_log_verbose(const char *fmt, ...);
+/** Utility for QRVERBOSE - use that instead. */
+KR_EXPORT KR_PRINTF(3)
+void kr_log_qverbose_impl(const struct kr_query *qry, const char *cls, const char *fmt, ...);
+
/**
* @brief Return true if the query has request log handler installed.
*/