summaryrefslogtreecommitdiff
path: root/src/logging
diff options
context:
space:
mode:
Diffstat (limited to 'src/logging')
-rw-r--r--src/logging/logging.c83
-rw-r--r--src/logging/logging.h35
-rw-r--r--src/logging/logging.test.c215
3 files changed, 0 insertions, 333 deletions
diff --git a/src/logging/logging.c b/src/logging/logging.c
deleted file mode 100644
index 2a63a77..0000000
--- a/src/logging/logging.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "logging/logging.h"
-
-
-struct honey_log_info_t honey_log_info;
-
-
-static const char * honey_log_level_str_(enum honey_log_level_t level)
-{
- switch(honey_log_info.log_level) {
- case DEBUG:
- return "DEBUG";
- break;
-
- case INFO:
- return "INFO";
- break;
-
- case WARN:
- return "WARN";
- break;
-
- case ERROR:
- return "ERROR";
- break;
-
- case FATAL:
- return "FATAL";
- break;
-
- default:
- return NULL;
- break;
- }
-}
-
-const char * honey_log_level_str() {
- return honey_log_level_str_(honey_log_info.log_level);
-}
-
-
-void honey_log_set_level(enum honey_log_level_t level)
-{
- honey_log_info.log_level = level;
-}
-
-
-enum honey_log_level_t honey_log_get_level()
-{
- return honey_log_info.log_level;
-}
-
-
-void honey_log_set_file(FILE* file)
-{
- honey_log_info.log_file = file;
-}
-
-
-FILE * honey_log_get_file()
-{
- return honey_log_info.log_file;
-}
-
-
-void honey_log(enum honey_log_level_t required_level,
- const char *prefix,
- const char *fmt, ...)
-{
- if (honey_log_info.log_file == NULL)
- return;
-
- if (honey_log_info.log_level >= required_level) {
- va_list args;
- va_start(args, fmt);
- fprintf(honey_log_info.log_file, "%-8s",
- prefix);
- vfprintf(honey_log_info.log_file, fmt, args);
- va_end(args);
- }
-}
diff --git a/src/logging/logging.h b/src/logging/logging.h
deleted file mode 100644
index c8a5864..0000000
--- a/src/logging/logging.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef HONEY_LOGGING_H
-#define HONEY_LOGGING_H
-
-#include <stdio.h>
-
-enum honey_log_level_t
- { FATAL, ERROR, WARN, INFO, DEBUG };
-
-struct honey_log_info_t {
- enum honey_log_level_t log_level;
- FILE *log_file;
-};
-
-extern struct honey_log_info_t honey_log_info;
-
-const char * honey_log_level_str();
-
-
-void honey_log_set_level(enum honey_log_level_t level);
-enum honey_log_level_t honey_log_get_level();
-
-void honey_log_set_file(FILE *file);
-FILE * honey_log_get_file();
-
-void honey_log(enum honey_log_level_t required_level,
- const char *prefix,
- const char *fmt, ...);
-
-#define honey_debug(...) honey_log(DEBUG, "[DEBUG]", __VA_ARGS__)
-#define honey_info(...) honey_log(INFO, "[INFO]", __VA_ARGS__)
-#define honey_warn(...) honey_log(WARN, "[WARN]", __VA_ARGS__)
-#define honey_error(...) honey_log(ERROR, "[ERROR]", __VA_ARGS__)
-#define honey_fatal(...) honey_log(FATAL, "[FATAL]", __VA_ARGS__)
-
-#endif
diff --git a/src/logging/logging.test.c b/src/logging/logging.test.c
deleted file mode 100644
index e267b5d..0000000
--- a/src/logging/logging.test.c
+++ /dev/null
@@ -1,215 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "test/minunit.h"
-#include "test/suites.h"
-
-#include "logging/logging.h"
-
-
-/* test declarations */
-
-mu_test test_log_get_level();
-mu_test test_log_set_defaults();
-mu_test test_log_debug();
-mu_test test_log_info();
-mu_test test_log_warn();
-mu_test test_log_error();
-mu_test test_log_fatal();
-
-
-/* main suite */
-
-void honey_logging_tests()
-{
- mu_run_test("get log level strings", test_log_get_level);
- mu_run_test("print debug message", test_log_debug);
- mu_run_test("print info message", test_log_info);
- mu_run_test("print warning message", test_log_warn);
- mu_run_test("print error message", test_log_error);
- mu_run_test("print fatal error message", test_log_fatal);
-}
-
-
-/* ~~~~~~~~ test definitions ~~~~~~~~ */
-
-mu_test test_log_get_level()
-{
- honey_log_set_level(DEBUG);
- mu_assert_equal(DEBUG, honey_log_get_level());
- mu_assert_streq("DEBUG", honey_log_level_str());
-
- honey_log_set_level(INFO);
- mu_assert_equal(INFO, honey_log_get_level());
- mu_assert_streq("INFO", honey_log_level_str());
-
- honey_log_set_level(WARN);
- mu_assert_equal(WARN, honey_log_get_level());
- mu_assert_streq("WARN", honey_log_level_str());
-
- honey_log_set_level(ERROR);
- mu_assert_equal(ERROR, honey_log_get_level());
- mu_assert_streq("ERROR", honey_log_level_str());
-
- honey_log_set_level(FATAL);
- mu_assert_equal(FATAL, honey_log_get_level());
- mu_assert_streq("FATAL", honey_log_level_str());
-
- return 0;
-}
-
-
-mu_test test_log_debug()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_debug("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(DEBUG);
- mu_assert_equal(honey_log_get_level(), DEBUG);
-
- honey_debug("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[DEBUG] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_info()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_info("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(INFO);
- mu_assert_equal(honey_log_get_level(), INFO);
-
- honey_info("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[INFO] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_warn()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_warn("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(WARN);
- mu_assert_equal(honey_log_get_level(), WARN);
-
- honey_warn("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[WARN] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_error()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_error("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(ERROR);
- mu_assert_equal(honey_log_get_level(), ERROR);
-
- honey_error("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[ERROR] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_fatal()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(-1);
- mu_assert_equal(honey_log_get_level(), -1);
-
- honey_fatal("hello, %s!", "world");
- fflush(stream);
- // all error levels will print fatal messagesf
- mu_assert_streq(buffer, "[FATAL] hello, world!");
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_fatal("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[FATAL] hello, world![FATAL] hello, world!");
- free(buffer);
-
- return 0;
-}