diff --git a/src/logging.c b/src/logging.c index 2ace73e..c738bfa 100644 --- a/src/logging.c +++ b/src/logging.c @@ -7,6 +7,7 @@ #include #include #include "ucore/logging.h" +#include "ucore/utils.h" struct uc_log_destination { @@ -59,23 +60,39 @@ static const struct uc_log_module g_unknown_module = { //this list an anything contained within it. static SLIST_HEAD(, uc_log_destination) g_destinations; static int uc_log_reopen_file(struct uc_log_destination *dest); +//Uses enum UC_LOG_LEVEL as index +static const char *const g_debug_levels[] = { + "NONE", + "DEBUG", + "UNKNOWN_2", + "INFO", + "UNKNOWN_4" + "WARNING", + "UNKNOWN_6", + "ERROR" +}; inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l) { - switch(l) { - case UC_LL_NONE: - return "NONE"; - case UC_LL_DEBUG: - return "DEBUG"; - case UC_LL_INFO: - return "INFO"; - case UC_LL_WARNING: - return "WARNING"; - case UC_LL_ERROR: - return "ERROR"; + if (l >= 0 && l < (int)ARRAY_SIZE(g_debug_levels)) { + return g_debug_levels[l]; + } else { + return "???"; + } +} + +//returns -1 if the string is not a known log level +static enum UC_LOG_LEVEL uc_str_2_ll(const char *str) +{ + size_t i; + + for (i = 0; i < ARRAY_SIZE(g_debug_levels); i++) { + if (strcmp(str, g_debug_levels[i]) == 0) { + return (int)i; + } } - return "???"; + return -1; } static inline int uc_ll_2_syslog(enum UC_LOG_LEVEL l)