From: Lukáš Ježek Date: Tue, 4 May 2021 08:39:33 +0000 (+0200) Subject: log: remove kr_verbose_set X-Git-Tag: v5.4.0~2^2~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e476c0eb7ba1d34926b3b456694282c734bdebf2;p=thirdparty%2Fknot-resolver.git log: remove kr_verbose_set --- diff --git a/daemon/engine.c b/daemon/engine.c index 3ad80f474..7f9525f37 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -144,10 +144,13 @@ static int l_quit(lua_State *L) /** Toggle verbose mode. */ static int l_verbose(lua_State *L) { - if (lua_isboolean(L, 1) || lua_isnumber(L, 1)) { - kr_verbose_set(lua_toboolean(L, 1)); + 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; } - lua_pushboolean(L, kr_verbose_status); + + lua_pushboolean(L, kr_log_level_set(level) == LOG_DEBUG); return 1; } diff --git a/daemon/main.c b/daemon/main.c index 3c300da52..e24a7653f 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -263,10 +263,7 @@ static int parse_args(int argc, char **argv, struct args *args) args->interactive = false; break; case 'v': - kr_verbose_set(true); -#ifdef NOVERBOSELOG - kr_log_info("--verbose flag has no effect due to compilation with -DNOVERBOSELOG.\n"); -#endif + kr_log_level_set(LOG_DEBUG); break; case 'q': args->quiet = true; diff --git a/lib/log.c b/lib/log.c index ad140c1f7..b5bb4da24 100644 --- a/lib/log.c +++ b/lib/log.c @@ -3,6 +3,7 @@ */ #include +#include #include "lib/log.h" log_level_t kr_log_level = LOG_CRIT; @@ -16,6 +17,34 @@ void kr_log_fmt(log_level_t level, const char *fmt, ...) va_end(args); } +static void kres_gnutls_log(int level, const char *message) +{ + kr_log_debug("[gnutls] (%d) %s", level, message); +} + +int kr_log_level_set(log_level_t level) +{ + if (level < LOG_CRIT || level > LOG_DEBUG) + return kr_log_level; + + kr_log_level = 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) { + gnutls_global_set_log_function(kres_gnutls_log); + } + gnutls_global_set_log_level(level); + + return kr_log_level; + +} + +log_level_t kr_log_level_get(void) +{ + return kr_log_level; +} + void kr_log_init(log_level_t level) { kr_log_level = level; diff --git a/lib/log.h b/lib/log.h index 1dd1d8c1a..a855768f8 100644 --- a/lib/log.h +++ b/lib/log.h @@ -18,6 +18,8 @@ typedef enum { KR_EXPORT KR_PRINTF(2) void kr_log_fmt(log_level_t level, const char *fmt, ...); KR_EXPORT extern log_level_t kr_log_level; +KR_EXPORT int kr_log_level_set(log_level_t level); +KR_EXPORT log_level_t kr_log_level_get(void); void kr_log_init(log_level_t level); #define kr_log_debug(fmt, ...) kr_log_fmt(LOG_DEBUG, fmt, ## __VA_ARGS__) diff --git a/lib/utils.c b/lib/utils.c index 625fdb2e4..b37c13b1f 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -14,7 +14,6 @@ #include "lib/selection.h" #include "lib/resolve.h" -#include #include #include #include @@ -34,7 +33,6 @@ /* Always compile-in log symbols, even if disabled. */ #undef kr_verbose_status -#undef kr_verbose_set /* Logging & debugging */ bool kr_verbose_status = false; @@ -71,6 +69,7 @@ recover: errno = errno_orig; } + /* * Macros. */ @@ -94,26 +93,6 @@ static inline int u16tostr(uint8_t *dst, uint16_t num) /* * Cleanup callbacks. */ -static void kres_gnutls_log(int level, const char *message) -{ - kr_log_verbose("[gnutls] (%d) %s", level, message); -} - -bool kr_verbose_set(bool status) -{ -#ifndef NOVERBOSELOG - kr_verbose_status = status; - - /* gnutls logs messages related to our TLS and also libdnssec, - * and the logging is set up in a global way only */ - if (status) { - gnutls_global_set_log_function(kres_gnutls_log); - } - gnutls_global_set_log_level(status ? 5 : 0); -#endif - return kr_verbose_status; -} - static void kr_vlog_req( const struct kr_request * const req, uint32_t qry_uid, const unsigned int indent, const char *source, const char *fmt, diff --git a/lib/utils.h b/lib/utils.h index bcea6a01c..6fb1a76bc 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -100,9 +100,6 @@ static inline bool kr_assert_func(bool result, const char *expr, const char *fun /** Whether in --verbose mode. Only use this for reading. */ KR_EXPORT extern bool kr_verbose_status; -/** Set --verbose mode. Not available if compiled with -DNOVERBOSELOG. */ -KR_EXPORT bool kr_verbose_set(bool status); - /** * @brief Return true if the query has request log handler installed. */ diff --git a/utils/cache_gc/main.c b/utils/cache_gc/main.c index 4656073a7..2e863e6bb 100644 --- a/utils/cache_gc/main.c +++ b/utils/cache_gc/main.c @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) cfg.dry_run = true; break; case 'v': - kr_verbose_set(true); + kr_log_level_set(LOG_DEBUG); break; case ':': case '?':