Use static array for log level strings

This commit is contained in:
Nils O. Selåsdal
2013-06-05 20:51:53 +02:00
parent f2bbca8718
commit 972381bf13
+29 -12
View File
@@ -7,6 +7,7 @@
#include <syslog.h>
#include <sys/queue.h>
#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 "???";
}
}
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 -1;
}
static inline int uc_ll_2_syslog(enum UC_LOG_LEVEL l)