return true;
}
+static void
+logtype_set_level(uint32_t type, uint32_t level)
+{
+ uint32_t current = rte_logs.dynamic_types[type].loglevel;
+
+ if (current != level) {
+ rte_logs.dynamic_types[type].loglevel = level;
+ RTE_LOG(DEBUG, EAL, "%s log level changed from %s to %s\n",
+ rte_logs.dynamic_types[type].name == NULL ?
+ "" : rte_logs.dynamic_types[type].name,
+ eal_log_level2str(current),
+ eal_log_level2str(level));
+ }
+}
+
int
rte_log_set_level(uint32_t type, uint32_t level)
{
if (level > RTE_LOG_MAX)
return -1;
- rte_logs.dynamic_types[type].loglevel = level;
+ logtype_set_level(type, level);
return 0;
}
continue;
if (regexec(&r, rte_logs.dynamic_types[i].name, 0,
NULL, 0) == 0)
- rte_logs.dynamic_types[i].loglevel = level;
+ logtype_set_level(i, level);
}
regfree(&r);
continue;
if (fnmatch(pattern, rte_logs.dynamic_types[i].name, 0) == 0)
- rte_logs.dynamic_types[i].loglevel = level;
+ logtype_set_level(i, level);
}
return 0;
return -1;
}
-/* register an extended log type, assuming table is large enough, and id
- * is not yet registered.
- */
static int
-log_register(const char *name, int id)
-{
- char *dup_name = strdup(name);
-
- if (dup_name == NULL)
- return -ENOMEM;
-
- rte_logs.dynamic_types[id].name = dup_name;
- rte_logs.dynamic_types[id].loglevel = RTE_LOG_INFO;
-
- return id;
-}
-
-/* register an extended log type */
-int
-rte_log_register(const char *name)
+log_register(const char *name, uint32_t level)
{
struct rte_log_dynamic_type *new_dynamic_types;
- int id, ret;
+ int id;
id = log_lookup(name);
if (id >= 0)
return -ENOMEM;
rte_logs.dynamic_types = new_dynamic_types;
- ret = log_register(name, rte_logs.dynamic_types_len);
- if (ret < 0)
- return ret;
+ id = rte_logs.dynamic_types_len;
+ memset(&rte_logs.dynamic_types[id], 0,
+ sizeof(rte_logs.dynamic_types[id]));
+ rte_logs.dynamic_types[id].name = strdup(name);
+ if (rte_logs.dynamic_types[id].name == NULL)
+ return -ENOMEM;
+ logtype_set_level(id, level);
rte_logs.dynamic_types_len++;
- return ret;
+ return id;
+}
+
+/* register an extended log type */
+int
+rte_log_register(const char *name)
+{
+ return log_register(name, RTE_LOG_INFO);
}
/* Register an extended log type and try to pick its level from EAL options */
{
struct rte_eal_opt_loglevel *opt_ll;
uint32_t level = level_def;
- int type;
-
- type = rte_log_register(name);
- if (type < 0)
- return type;
TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
if (opt_ll->level > RTE_LOG_MAX)
}
}
- rte_logs.dynamic_types[type].loglevel = level;
-
- return type;
+ return log_register(name, level);
}
struct logtype {
return;
/* register legacy log types */
- for (i = 0; i < RTE_DIM(logtype_strings); i++)
- log_register(logtype_strings[i].logtype,
- logtype_strings[i].log_id);
+ for (i = 0; i < RTE_DIM(logtype_strings); i++) {
+ rte_logs.dynamic_types[logtype_strings[i].log_id].name =
+ strdup(logtype_strings[i].logtype);
+ logtype_set_level(logtype_strings[i].log_id, RTE_LOG_INFO);
+ }
rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
}