Commit 1d42962e authored by Dan Winship's avatar Dan Winship

logging: fix "nmcli gen log level FOO"

The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:

danw@laptop:NetworkManager> nmcli g log
LEVEL  DOMAINS
INFO   PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...

danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL  DOMAINS
DEBUG  PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
parent 2b87dbb2
......@@ -159,101 +159,97 @@ nm_logging_setup (const char *level,
GString *unrecognized = NULL;
guint64 new_logging[LOGL_MAX];
guint32 new_log_level = log_level;
char **tmp, **iter;
int i;
if (!domains)
domains = log_domains ? log_domains : "DEFAULT";
for (i = 0; i < LOGL_MAX; i++)
new_logging[i] = 0;
/* levels */
if (level && strlen (level)) {
if (level && *level) {
if (!match_log_level (level, &new_log_level, error))
return FALSE;
}
/* domains */
if (domains && strlen (domains)) {
char **tmp, **iter;
tmp = g_strsplit_set (domains, ", ", 0);
for (iter = tmp; iter && *iter; iter++) {
const LogDesc *diter;
guint32 domain_log_level;
guint64 bits;
char *p;
if (!strlen (*iter))
continue;
p = strchr (*iter, ':');
if (p) {
*p = '\0';
if (!match_log_level (p + 1, &domain_log_level, error)) {
g_strfreev (tmp);
return FALSE;
}
} else
domain_log_level = new_log_level;
bits = 0;
/* Check for combined domains */
if (!g_ascii_strcasecmp (*iter, LOGD_ALL_STRING))
bits = LOGD_ALL;
else if (!g_ascii_strcasecmp (*iter, LOGD_DEFAULT_STRING))
bits = LOGD_DEFAULT;
else if (!g_ascii_strcasecmp (*iter, LOGD_DHCP_STRING))
bits = LOGD_DHCP;
else if (!g_ascii_strcasecmp (*iter, LOGD_IP_STRING))
bits = LOGD_IP;
/* Check for compatibility domains */
else if (!g_ascii_strcasecmp (*iter, "HW"))
bits = LOGD_PLATFORM;
else {
for (diter = &domain_descs[0]; diter->name; diter++) {
if (!g_ascii_strcasecmp (diter->name, *iter)) {
bits = diter->num;
break;
}
}
}
if (!domains || !*domains)
domains = log_domains ? log_domains : "DEFAULT";
tmp = g_strsplit_set (domains, ", ", 0);
for (iter = tmp; iter && *iter; iter++) {
const LogDesc *diter;
guint32 domain_log_level;
guint64 bits;
char *p;
if (!strlen (*iter))
continue;
if (!bits) {
if (!bad_domains) {
g_set_error (error, NM_LOGGING_ERROR, NM_LOGGING_ERROR_UNKNOWN_DOMAIN,
_("Unknown log domain '%s'"), *iter);
return FALSE;
p = strchr (*iter, ':');
if (p) {
*p = '\0';
if (!match_log_level (p + 1, &domain_log_level, error)) {
g_strfreev (tmp);
return FALSE;
}
} else
domain_log_level = new_log_level;
bits = 0;
/* Check for combined domains */
if (!g_ascii_strcasecmp (*iter, LOGD_ALL_STRING))
bits = LOGD_ALL;
else if (!g_ascii_strcasecmp (*iter, LOGD_DEFAULT_STRING))
bits = LOGD_DEFAULT;
else if (!g_ascii_strcasecmp (*iter, LOGD_DHCP_STRING))
bits = LOGD_DHCP;
else if (!g_ascii_strcasecmp (*iter, LOGD_IP_STRING))
bits = LOGD_IP;
/* Check for compatibility domains */
else if (!g_ascii_strcasecmp (*iter, "HW"))
bits = LOGD_PLATFORM;
else {
for (diter = &domain_descs[0]; diter->name; diter++) {
if (!g_ascii_strcasecmp (diter->name, *iter)) {
bits = diter->num;
break;
}
}
}
if (unrecognized)
g_string_append (unrecognized, ", ");
else
unrecognized = g_string_new (NULL);
g_string_append (unrecognized, *iter);
continue;
if (!bits) {
if (!bad_domains) {
g_set_error (error, NM_LOGGING_ERROR, NM_LOGGING_ERROR_UNKNOWN_DOMAIN,
_("Unknown log domain '%s'"), *iter);
return FALSE;
}
for (i = 0; i < domain_log_level; i++)
new_logging[i] &= ~bits;
for (i = domain_log_level; i < LOGL_MAX; i++)
new_logging[i] |= bits;
if (unrecognized)
g_string_append (unrecognized, ", ");
else
unrecognized = g_string_new (NULL);
g_string_append (unrecognized, *iter);
continue;
}
g_strfreev (tmp);
if (log_domains != (char *)domains) {
g_free (log_domains);
log_domains = g_strdup (domains);
}
for (i = 0; i < domain_log_level; i++)
new_logging[i] &= ~bits;
for (i = domain_log_level; i < LOGL_MAX; i++)
new_logging[i] |= bits;
}
g_strfreev (tmp);
for (i = 0; i < LOGL_MAX; i++)
logging[i] = new_logging[i];
if (log_domains != (char *)domains) {
g_free (log_domains);
log_domains = g_strdup (domains);
}
log_level = new_log_level;
for (i = 0; i < LOGL_MAX; i++)
logging[i] = new_logging[i];
if (unrecognized)
*bad_domains = g_string_free (unrecognized, FALSE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment