diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/logging/logging.h | 12 | ||||
| -rw-r--r-- | src/test/logging/logging_tests.c | 6 | 
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!");  | 
