From 3d48d8d62349ba4b66dc4bc5c3582486baa872d6 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Thu, 21 Mar 2024 00:58:13 +0100 Subject: Add global log level --- any_log.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'any_log.h') diff --git a/any_log.h b/any_log.h index d9d575d..a0f91d1 100644 --- a/any_log.h +++ b/any_log.h @@ -99,6 +99,8 @@ typedef enum { #define ANY_LOG_ATTRIBUTE(...) #endif +extern any_log_level_t any_log_level; + extern const char *any_log_level_strings[ANY_LOG_ALL]; ANY_LOG_ATTRIBUTE(pure) @@ -123,6 +125,12 @@ void any_log_format(any_log_level_t level, const char *module, #include #include +#ifndef ANY_LOG_DEFAULT_LEVEL +#define ANY_LOG_DEFAULT_LEVEL ANY_LOG_INFO +#endif + +any_log_level_t any_log_level = ANY_LOG_DEFAULT_LEVEL; + #ifndef ANY_LOG_PANIC_STRING #define ANY_LOG_PANIC_STRING "panic" #endif @@ -201,6 +209,9 @@ void any_log_exit(const char *module, const char *func) void any_log_format(any_log_level_t level, const char *module, const char *func, const char *format, ...) { + if (level > any_log_level) + return; + fprintf(stdout, ANY_LOG_FORMAT_BEFORE(level, module, func)); va_list args; -- cgit v1.2.3