summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/log.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/common/log.c b/common/log.c
index 45e46dd520..d5f1cc5077 100644
--- a/common/log.c
+++ b/common/log.c
@@ -10,9 +10,76 @@
#include <common.h>
#include <log.h>
#include <malloc.h>
+#include <dm/uclass.h>
DECLARE_GLOBAL_DATA_PTR;
+static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = {
+ "none",
+ "arch",
+ "board",
+ "core",
+ "driver-model",
+ "device-tree",
+};
+
+static const char *log_level_name[LOGL_COUNT] = {
+ "EMERG",
+ "ALERT",
+ "CRIT",
+ "ERR",
+ "WARNING",
+ "NOTICE",
+ "INFO",
+ "DEBUG",
+ "CONTENT",
+ "IO",
+};
+
+const char *log_get_cat_name(enum log_category_t cat)
+{
+ if (cat > LOGC_COUNT)
+ return "invalid";
+ if (cat >= LOGC_NONE)
+ return log_cat_name[cat - LOGC_NONE];
+
+ return uclass_get_name((enum uclass_id)cat);
+}
+
+enum log_category_t log_get_cat_by_name(const char *name)
+{
+ enum uclass_id id;
+ int i;
+
+ for (i = LOGC_NONE; i < LOGC_COUNT; i++)
+ if (!strcmp(name, log_cat_name[i - LOGC_NONE]))
+ return i;
+ id = uclass_get_by_name(name);
+ if (id != UCLASS_INVALID)
+ return (enum log_category_t)id;
+
+ return LOGC_NONE;
+}
+
+const char *log_get_level_name(enum log_level_t level)
+{
+ if (level >= LOGL_COUNT)
+ return "INVALID";
+ return log_level_name[level];
+}
+
+enum log_level_t log_get_level_by_name(const char *name)
+{
+ int i;
+
+ for (i = 0; i < LOGL_COUNT; i++) {
+ if (!strcasecmp(log_level_name[i], name))
+ return i;
+ }
+
+ return LOGL_NONE;
+}
+
static struct log_device *log_device_find_by_name(const char *drv_name)
{
struct log_device *ldev;