Use static array for log level strings
This commit is contained in:
+29
-12
@@ -7,6 +7,7 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include "ucore/logging.h"
|
#include "ucore/logging.h"
|
||||||
|
#include "ucore/utils.h"
|
||||||
|
|
||||||
|
|
||||||
struct uc_log_destination {
|
struct uc_log_destination {
|
||||||
@@ -59,23 +60,39 @@ static const struct uc_log_module g_unknown_module = {
|
|||||||
//this list an anything contained within it.
|
//this list an anything contained within it.
|
||||||
static SLIST_HEAD(, uc_log_destination) g_destinations;
|
static SLIST_HEAD(, uc_log_destination) g_destinations;
|
||||||
static int uc_log_reopen_file(struct uc_log_destination *dest);
|
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)
|
inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l)
|
||||||
{
|
{
|
||||||
switch(l) {
|
if (l >= 0 && l < (int)ARRAY_SIZE(g_debug_levels)) {
|
||||||
case UC_LL_NONE:
|
return g_debug_levels[l];
|
||||||
return "NONE";
|
} else {
|
||||||
case UC_LL_DEBUG:
|
return "???";
|
||||||
return "DEBUG";
|
}
|
||||||
case UC_LL_INFO:
|
|
||||||
return "INFO";
|
|
||||||
case UC_LL_WARNING:
|
|
||||||
return "WARNING";
|
|
||||||
case UC_LL_ERROR:
|
|
||||||
return "ERROR";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
static inline int uc_ll_2_syslog(enum UC_LOG_LEVEL l)
|
||||||
|
|||||||
Reference in New Issue
Block a user