summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-09-23 23:45:47 -0500
committersanine <sanine.not@pm.me>2021-09-23 23:45:47 -0500
commit921f1a46bbccbdf9dcadbd7017ec0c575d2bed1f (patch)
tree22d09dfa53930e1f4bf266f7d24376c6f453af19 /src
parentf9f790c5cd3de6cd82ebf08c1f1695d411dd4a60 (diff)
fix debug required logging level
Diffstat (limited to 'src')
-rw-r--r--src/logging/logging.h12
-rw-r--r--src/test/logging/logging_tests.c6
2 files changed, 15 insertions, 3 deletions
diff --git a/src/logging/logging.h b/src/logging/logging.h
index 4357ae1..8f4d174 100644
--- a/src/logging/logging.h
+++ b/src/logging/logging.h
@@ -5,7 +5,7 @@
struct honey_log_info {
- enum { DEBUG, INFO, WARN, ERROR, FATAL } log_level;
+ enum { FATAL, ERROR, WARN, INFO, DEBUG } log_level;
FILE *debug_out;
FILE *info_out;
FILE *warn_out;
@@ -15,8 +15,14 @@ struct honey_log_info {
const char * honey_log_level_str_(struct honey_log_info *info);
-#define honey_debug_(info, ...) \
- fprintf(info.debug_out, "[DEBUG] " __VA_ARGS__)
+#define honey_log_(info, required_level, prefix, ...) do { \
+ if (info.log_level >= required_level) { \
+ fprintf(info.debug_out, prefix " " __VA_ARGS__); \
+ } \
+ } while(0)
+
+#define honey_debug_(info, ...) \
+ honey_log_(info, DEBUG, "[DEBUG]", __VA_ARGS__)
#endif
diff --git a/src/test/logging/logging_tests.c b/src/test/logging/logging_tests.c
index ee00d8e..2d4ced9 100644
--- a/src/test/logging/logging_tests.c
+++ b/src/test/logging/logging_tests.c
@@ -58,7 +58,13 @@ mu_test test_log_debug()
struct honey_log_info info;
info.debug_out = stream;
+ info.log_level = FATAL;
+
+ honey_debug_(info, "hello, world!");
+ fflush(stream);
+ mu_assert_streq(buffer, "");
+ info.log_level = DEBUG;
honey_debug_(info, "hello, world!");
fclose(stream);
mu_assert_streq(buffer, "[DEBUG] hello, world!");