context: support letter codes for log.level

Letter codes instead of numbers for log levels are allowed in
PIPEWIRE_DEBUG.

Support them also for log.level in context properties and metadata.

Add a few alias letter codes to harmonize them with what WirePlumber 0.5
supports.
This commit is contained in:
Pauli Virtanen 2023-12-09 11:25:43 +02:00 committed by Wim Taymans
parent 80bf28edfd
commit 9d779300af
5 changed files with 33 additions and 11 deletions

View file

@ -263,8 +263,14 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop,
}
if (getenv("PIPEWIRE_DEBUG") == NULL &&
(str = pw_properties_get(properties, "log.level")) != NULL)
pw_log_set_level(atoi(str));
(str = pw_properties_get(properties, "log.level")) != NULL) {
enum spa_log_level lev;
if (pw_parse_log_level(str, &lev))
pw_log_set_level(lev);
else
pw_log_warn("%p: invalid log.level in context properties", this);
}
if (pw_properties_get_bool(properties, "mem.mlock-all", false)) {
if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0)

View file

@ -18,8 +18,6 @@
SPA_LOG_IMPL(default_log);
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_WARN
SPA_EXPORT
enum spa_log_level pw_log_level = DEFAULT_LOG_LEVEL;

View file

@ -469,15 +469,23 @@ static struct spa_log *load_journal_logger(struct support *support,
}
#endif
static bool
parse_log_level(const char *str, enum spa_log_level *l)
bool
pw_parse_log_level(const char *str, enum spa_log_level *l)
{
uint32_t lvl;
if (!str)
return false;
if (strlen(str) == 1) {
switch(str[0]) {
/* SPA levels, plus a few duplicate codes that
* WirePlumber supports for some GLib levels. */
switch (str[0]) {
case 'X': lvl = SPA_LOG_LEVEL_NONE; break;
case 'F': lvl = SPA_LOG_LEVEL_NONE; break; /* fatal */
case 'E': lvl = SPA_LOG_LEVEL_ERROR; break;
case 'W': lvl = SPA_LOG_LEVEL_WARN; break;
case 'N': lvl = SPA_LOG_LEVEL_WARN; break; /* notice */
case 'I': lvl = SPA_LOG_LEVEL_INFO; break;
case 'D': lvl = SPA_LOG_LEVEL_DEBUG; break;
case 'T': lvl = SPA_LOG_LEVEL_TRACE; break;
@ -491,6 +499,7 @@ check_int:
if (lvl > SPA_LOG_LEVEL_TRACE)
return false;
}
*l = lvl;
return true;
}
@ -524,11 +533,11 @@ parse_pw_debug_env(void)
char *tok[2];
n_tok = pw_split_ip(tokens[i], ":", SPA_N_ELEMENTS(tok), tok);
if (n_tok == 2 && parse_log_level(tok[1], &lvl)) {
if (n_tok == 2 && pw_parse_log_level(tok[1], &lvl)) {
char *pattern = tok[0];
pos += spa_scnprintf(pos, end - pos, "{ %s = %d },",
pattern, lvl);
} else if (n_tok == 1 && parse_log_level(tok[0], &lvl)) {
} else if (n_tok == 1 && pw_parse_log_level(tok[0], &lvl)) {
pw_log_set_level(lvl);
} else {
pw_log_warn("Ignoring invalid format in PIPEWIRE_DEBUG: '%s'",

View file

@ -30,6 +30,7 @@ struct ucred {
#define MAX_RATES 32u
#define CLOCK_MIN_QUANTUM 4u
#define CLOCK_MAX_QUANTUM 65536u
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_WARN
struct settings {
uint32_t log_level;
@ -1294,6 +1295,8 @@ void pw_settings_clean(struct pw_context *context);
bool pw_should_dlclose(void);
bool pw_parse_log_level(const char *str, enum spa_log_level *l);
/** \endcond */
#ifdef __cplusplus

View file

@ -142,8 +142,14 @@ static int metadata_property(void *data, uint32_t subject, const char *key,
return 0;
if (spa_streq(key, "log.level")) {
v = value ? atoi(value) : 3;
pw_log_set_level(v);
enum spa_log_level lev;
if (!value)
pw_log_set_level(DEFAULT_LOG_LEVEL);
else if (pw_parse_log_level(value, &lev))
pw_log_set_level(lev);
else
pw_log_warn("Ignoring unknown settings metadata log.level '%s'", value);
} else if (spa_streq(key, "clock.rate")) {
v = value ? atoi(value) : 0;
s->clock_rate = v == 0 ? d->clock_rate : v;