aboutsummaryrefslogtreecommitdiff
path: root/any_log.h
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-03-21 00:58:13 +0100
committerFederico Angelilli <code@fedang.net>2024-03-21 00:58:13 +0100
commit3d48d8d62349ba4b66dc4bc5c3582486baa872d6 (patch)
tree8fc01a8185be93b3ca381c8d5c3c50e4d002af3e /any_log.h
parent1d793c34b036cd094369ae56f15f5731b03c5bee (diff)
Add global log level
Diffstat (limited to 'any_log.h')
-rw-r--r--any_log.h11
1 files changed, 11 insertions, 0 deletions
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 <stdlib.h>
#include <string.h>
+#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;