diff options
-rw-r--r-- | src/logging/logging.h | 12 | ||||
-rw-r--r-- | src/test/logging/logging_tests.c | 26 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/logging/logging.h b/src/logging/logging.h index 87436e5..4357ae1 100644 --- a/src/logging/logging.h +++ b/src/logging/logging.h @@ -1,10 +1,22 @@ #ifndef HONEY_LOGGING_H #define HONEY_LOGGING_H +#include <stdio.h> + + struct honey_log_info { enum { DEBUG, INFO, WARN, ERROR, FATAL } log_level; + FILE *debug_out; + FILE *info_out; + FILE *warn_out; + FILE *error_out; + FILE *fatal_out; }; const char * honey_log_level_str_(struct honey_log_info *info); +#define honey_debug_(info, ...) \ + fprintf(info.debug_out, "[DEBUG] " __VA_ARGS__) + + #endif diff --git a/src/test/logging/logging_tests.c b/src/test/logging/logging_tests.c index 2a07d30..ee00d8e 100644 --- a/src/test/logging/logging_tests.c +++ b/src/test/logging/logging_tests.c @@ -1,3 +1,6 @@ +#include <stdio.h> +#include <stdlib.h> + #include "test/minunit.h" #include "test/suites.h" @@ -7,6 +10,7 @@ /* test declarations */ mu_test test_log_get_level(); +mu_test test_log_debug(); /* main suite */ @@ -14,6 +18,7 @@ mu_test test_log_get_level(); void honey_logging_tests() { mu_run_test("get log level strings", test_log_get_level); + mu_run_test("print debug message", test_log_debug); } @@ -40,3 +45,24 @@ mu_test test_log_get_level() return 0; } + + +mu_test test_log_debug() +{ + FILE *stream; + char *buffer; + size_t len; + + stream = open_memstream(&buffer, &len); + mu_assert_unequal(stream, NULL); + + struct honey_log_info info; + info.debug_out = stream; + + honey_debug_(info, "hello, world!"); + fclose(stream); + mu_assert_streq(buffer, "[DEBUG] hello, world!"); + free(buffer); + + return 0; +} |