From: Lukáš Ježek Date: Tue, 4 May 2021 10:03:26 +0000 (+0200) Subject: log: remove kr_verbose_status X-Git-Tag: v5.4.0~2^2~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1167b2dbfe9158da85deda21e956b1ad1da98e5e;p=thirdparty%2Fknot-resolver.git log: remove kr_verbose_status --- diff --git a/daemon/engine.c b/daemon/engine.c index 7f9525f37..8617ef4b5 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -144,13 +144,11 @@ static int l_quit(lua_State *L) /** Toggle verbose mode. */ static int l_verbose(lua_State *L) { - log_level_t level = LOG_ERR; - if ((lua_isboolean(L, 1) && lua_toboolean(L, 1) == true) || - (lua_isnumber(L, 1) && lua_tointeger(L, 1) == LOG_DEBUG)) { - level = LOG_DEBUG; + if (lua_isboolean(L, 1) || lua_isnumber(L, 1)) { + kr_log_level_set(lua_toboolean(L, 1) == true ? LOG_DEBUG : LOG_DEFAULT_LEVEL); } - lua_pushboolean(L, kr_log_level_set(level) == LOG_DEBUG); + lua_pushboolean(L, kr_log_level_get() == LOG_DEBUG); return 1; } diff --git a/daemon/io.c b/daemon/io.c index 4d9cb7ed5..056115f59 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -281,7 +281,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) } if (nread < 0 || !buf->base) { - if (kr_verbose_status) { + if (KR_LOG_LEVEL_IS(LOG_DEBUG)) { struct sockaddr *peer = session_get_peer(s); char *peer_str = kr_straddr(peer); kr_log_verbose("[io] => connection to '%s' closed by peer (%s)\n", @@ -300,7 +300,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) Decode data free space in session wire buffer. */ consumed = tls_process_input_data(s, (const uint8_t *)buf->base, nread); if (consumed < 0) { - if (kr_verbose_status) { + if (KR_LOG_LEVEL_IS(LOG_DEBUG)) { struct sockaddr *peer = session_get_peer(s); char *peer_str = kr_straddr(peer); kr_log_verbose("[io] => connection to '%s': " @@ -319,7 +319,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) if (session_flags(s)->has_http) { consumed = http_process_input_data(s, data, data_len); if (consumed < 0) { - if (kr_verbose_status) { + if (KR_LOG_LEVEL_IS(LOG_DEBUG)) { struct sockaddr *peer = session_get_peer(s); char *peer_str = kr_straddr(peer); kr_log_verbose("[io] => connection to '%s': " diff --git a/lib/cache/nsec1.c b/lib/cache/nsec1.c index 32e969eb7..f6bf72758 100644 --- a/lib/cache/nsec1.c +++ b/lib/cache/nsec1.c @@ -424,7 +424,7 @@ int nsec1_src_synth(struct key *k, struct answer *ans, const knot_dname_t *clenc if (kr_fails_assert(nsec_rr)) return kr_error(EFAULT); const uint32_t new_ttl_log = - kr_verbose_status ? nsec_rr->ttl : -1; + KR_LOG_LEVEL_IS(LOG_DEBUG) ? nsec_rr->ttl : -1; const uint8_t *bm = knot_nsec_bitmap(nsec_rr->rrs.rdata); uint16_t bm_size = knot_nsec_bitmap_len(nsec_rr->rrs.rdata); int ret; diff --git a/lib/log.c b/lib/log.c index b5bb4da24..5bcb14920 100644 --- a/lib/log.c +++ b/lib/log.c @@ -12,7 +12,7 @@ void kr_log_fmt(log_level_t level, const char *fmt, ...) { va_list args; va_start(args, fmt); - if (level <= kr_log_level) + if (KR_LOG_LEVEL_IS(level)) vfprintf(stdout, fmt, args); va_end(args); } @@ -31,10 +31,11 @@ int kr_log_level_set(log_level_t level) /* gnutls logs messages related to our TLS and also libdnssec, * and the logging is set up in a global way only */ - if (kr_log_level >= LOG_DEBUG) { + if (KR_LOG_LEVEL_IS(LOG_DEBUG)) { gnutls_global_set_log_function(kres_gnutls_log); } - gnutls_global_set_log_level(level); + + gnutls_global_set_log_level(kr_log_level_get() == LOG_DEBUG ? 5 : 0); return kr_log_level; diff --git a/lib/log.h b/lib/log.h index a855768f8..476b18b43 100644 --- a/lib/log.h +++ b/lib/log.h @@ -30,3 +30,5 @@ void kr_log_init(log_level_t level); #define kr_log_fatal(fmt, ...) kr_log_fmt(LOG_CRIT, fmt, ## __VA_ARGS__) #define kr_log_deprecate(fmt, ...) kr_log_fmt(LOG_WARNING, "deprecation WARNING: " fmt, ## __VA_ARGS__) + +#define KR_LOG_LEVEL_IS(exp) ((kr_log_level >= (exp)) ? true : false) diff --git a/lib/utils.c b/lib/utils.c index b37c13b1f..be6f21cad 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -31,11 +31,7 @@ #include #include -/* Always compile-in log symbols, even if disabled. */ -#undef kr_verbose_status - /* Logging & debugging */ -bool kr_verbose_status = false; bool kr_dbg_assertion_abort = DBG_ASSERTION_ABORT; int kr_dbg_assertion_fork = DBG_ASSERTION_FORK; @@ -69,7 +65,6 @@ recover: errno = errno_orig; } - /* * Macros. */ diff --git a/lib/utils.h b/lib/utils.h index 6fb1a76bc..f28b65e17 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -96,10 +96,6 @@ static inline bool kr_assert_func(bool result, const char *expr, const char *fun return result; } -/* Always export these, but override direct calls by macros conditionally. */ -/** Whether in --verbose mode. Only use this for reading. */ -KR_EXPORT extern bool kr_verbose_status; - /** * @brief Return true if the query has request log handler installed. */ @@ -133,15 +129,9 @@ void kr_log_req(const struct kr_request * const req, uint32_t qry_uid, KR_EXPORT KR_PRINTF(3) void kr_log_q(const struct kr_query *qry, const char *source, const char *fmt, ...); -#ifdef NOVERBOSELOG -/* Efficient compile-time disabling of verbose messages. */ -#define kr_verbose_status false -#define kr_verbose_set(x) -#endif - /** Block run in --verbose mode; optimized when not run. */ -#define VERBOSE_STATUS __builtin_expect(kr_verbose_status, false) -#define WITH_VERBOSE(query) if(__builtin_expect(kr_verbose_status || kr_log_qtrace_enabled(query), false)) +#define VERBOSE_STATUS __builtin_expect(KR_LOG_LEVEL_IS(LOG_DEBUG), false) +#define WITH_VERBOSE(query) if(__builtin_expect(KR_LOG_LEVEL_IS(LOG_DEBUG) || kr_log_qtrace_enabled(query), false)) #define kr_log_verbose if(VERBOSE_STATUS) printf #define KR_DNAME_GET_STR(dname_str, dname) \