config: fix documentation of --log-domains

The list of log domains in the --log-domains documentation had gotten
out of date. Fix this by adding nm_logging_all_domain_to_string()
(and, for completeness, nm_logging_all_levels_to_string()), and use
those to fill in the help string.
This commit is contained in:
Dan Winship
2013-03-11 12:23:57 -04:00
parent 3407726758
commit 8bb9ee8d3b
3 changed files with 65 additions and 9 deletions

View File

@@ -24,6 +24,7 @@
#include <stdio.h> #include <stdio.h>
#include "nm-config.h" #include "nm-config.h"
#include "nm-logging.h"
#include <glib/gi18n.h> #include <glib/gi18n.h>
@@ -138,25 +139,35 @@ static char *cli_connectivity_response;
static GOptionEntry config_options[] = { static GOptionEntry config_options[] = {
{ "config", 0, 0, G_OPTION_ARG_FILENAME, &cli_config_path, N_("Config file location"), N_("/path/to/config.file") }, { "config", 0, 0, G_OPTION_ARG_FILENAME, &cli_config_path, N_("Config file location"), N_("/path/to/config.file") },
{ "plugins", 0, 0, G_OPTION_ARG_STRING, &cli_plugins, N_("List of plugins separated by ','"), N_("plugin1,plugin2") }, { "plugins", 0, 0, G_OPTION_ARG_STRING, &cli_plugins, N_("List of plugins separated by ','"), N_("plugin1,plugin2") },
/* Translators: Do not translate the values in the square brackets */ { "log-level", 0, 0, G_OPTION_ARG_STRING, &cli_log_level, N_("Log level: one of [%s]"), "INFO" },
{ "log-level", 0, 0, G_OPTION_ARG_STRING, &cli_log_level, N_("Log level: one of [ERR, WARN, INFO, DEBUG]"), "INFO" },
{ "log-domains", 0, 0, G_OPTION_ARG_STRING, &cli_log_domains, { "log-domains", 0, 0, G_OPTION_ARG_STRING, &cli_log_domains,
/* Translators: Do not translate the values in the square brackets */ N_("Log domains separated by ',': any combination of [%s]"),
N_("Log domains separated by ',': any combination of\n" "PLATFORM,RFKILL,WIFI" },
" [NONE,HW,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,\n"
" WIFI_SCAN,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,\n"
" AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,WIMAX,\n"
" INFINIBAND,FIREWALL,ADSL]"),
"HW,RFKILL,WIFI" },
{ "connectivity-uri", 0, 0, G_OPTION_ARG_STRING, &cli_connectivity_uri, N_("An http(s) address for checking internet connectivity"), "http://example.com" }, { "connectivity-uri", 0, 0, G_OPTION_ARG_STRING, &cli_connectivity_uri, N_("An http(s) address for checking internet connectivity"), "http://example.com" },
{ "connectivity-interval", 0, 0, G_OPTION_ARG_INT, &cli_connectivity_interval, N_("The interval between connectivity checks (in seconds)"), "60" }, { "connectivity-interval", 0, 0, G_OPTION_ARG_INT, &cli_connectivity_interval, N_("The interval between connectivity checks (in seconds)"), "60" },
{ "connectivity-response", 0, 0, G_OPTION_ARG_STRING, &cli_connectivity_response, N_("The expected start of the response"), N_("Bingo!") }, { "connectivity-response", 0, 0, G_OPTION_ARG_STRING, &cli_connectivity_response, N_("The expected start of the response"), N_("Bingo!") },
{NULL} {NULL}
}; };
static gboolean config_options_inited;
GOptionEntry * GOptionEntry *
nm_config_get_options (void) nm_config_get_options (void)
{ {
if (!config_options_inited) {
int i;
for (i = 0; config_options[i].long_name; i++) {
if (!strcmp (config_options[i].long_name, "log-level")) {
config_options[i].description = g_strdup_printf (config_options[i].description,
nm_logging_all_levels_to_string ());
} else if (!strcmp (config_options[i].long_name, "log-domains")) {
config_options[i].description = g_strdup_printf (config_options[i].description,
nm_logging_all_domains_to_string ());
}
}
config_options_inited = TRUE;
}
return config_options; return config_options;
} }

View File

@@ -209,6 +209,25 @@ nm_logging_level_to_string (void)
return ""; return "";
} }
const char *
nm_logging_all_levels_to_string (void)
{
static GString *str;
if (G_UNLIKELY (!str)) {
const LogDesc *diter;
str = g_string_new (NULL);
for (diter = &level_descs[0]; diter->name; diter++) {
if (str->len)
g_string_append_c (str, ',');
g_string_append (str, diter->name);
}
}
return str->str;
}
char * char *
nm_logging_domains_to_string (void) nm_logging_domains_to_string (void)
{ {
@@ -226,6 +245,29 @@ nm_logging_domains_to_string (void)
return g_string_free (str, FALSE); return g_string_free (str, FALSE);
} }
const char *
nm_logging_all_domains_to_string (void)
{
static GString *str;
if (G_UNLIKELY (!str)) {
const LogDesc *diter;
str = g_string_new ("DEFAULT");
for (diter = &domain_descs[0]; diter->name; diter++) {
g_string_append_c (str, ',');
g_string_append (str, diter->name);
if (diter->num == LOGD_DHCP6)
g_string_append (str, ",DHCP");
else if (diter->num == LOGD_IP6)
g_string_append (str, ",IP");
}
g_string_append (str, ",ALL");
}
return str->str;
}
gboolean gboolean
nm_logging_level_enabled (guint32 level) nm_logging_level_enabled (guint32 level)
{ {

View File

@@ -108,6 +108,9 @@ char *nm_logging_domains_to_string (void);
gboolean nm_logging_level_enabled (guint32 level); gboolean nm_logging_level_enabled (guint32 level);
gboolean nm_logging_domain_enabled (guint32 domain); gboolean nm_logging_domain_enabled (guint32 domain);
const char *nm_logging_all_levels_to_string (void);
const char *nm_logging_all_domains_to_string (void);
/* Undefine the nm-utils.h logging stuff to ensure errors */ /* Undefine the nm-utils.h logging stuff to ensure errors */
#undef nm_get_timestamp #undef nm_get_timestamp
#undef nm_info #undef nm_info