logging: support an "OFF" logging level

The only way to disable logging for a domain entirely is to
omit the domain from the "domains" list. For example:

  "level=INFO, domains=PLATFORM,..."

Now add an explicit level "OFF" to facilitate configuration like:

  "level=INFO, domains=ALL,WIFI_SCAN:OFF"

It also supports
  "level=OFF, domains=PLATFORM:INFO"
but this is for the most part equivalent to
  "level=INFO, domains=PLATFORM"
This commit is contained in:
Thomas Haller
2015-08-01 14:12:34 +02:00
parent 655b85bfea
commit 8c3f1812ea
4 changed files with 16 additions and 9 deletions

View File

@@ -306,7 +306,7 @@ _nmcli_compl_ARGS()
case "${words[0]}" in
level)
if [[ "${#words[@]}" -eq 2 ]]; then
_nmcli_list "ERR WARN INFO DEBUG TRACE"
_nmcli_list "OFF ERR WARN INFO DEBUG TRACE"
return 0
fi
;;

View File

@@ -396,7 +396,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth
<varlistentry>
<term><varname>level</varname></term>
<listitem><para>The default logging verbosity level.
One of <literal>ERR</literal>,
One of <literal>OFF</literal>, <literal>ERR</literal>,
<literal>WARN</literal>, <literal>INFO</literal>,
<literal>DEBUG</literal>, <literal>TRACE</literal>. The ERR
level logs only critical errors. WARN logs warnings that may
@@ -419,7 +419,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth
ALL, DEFAULT, DHCP, IP.</para>
<para>You can specify per-domain log level overrides by
adding a colon and a log level to any domain. E.g.,
"<literal>WIFI:DEBUG</literal>".</para></listitem>
"<literal>WIFI:DEBUG,WIFI_SCAN:OFF</literal>".</para></listitem>
</varlistentry>
<varlistentry>
<para>Domain descriptions:

View File

@@ -53,7 +53,7 @@ nm_log_handler (const gchar *log_domain,
static NMLogLevel log_level = LOGL_INFO;
static char *log_domains;
static NMLogDomain logging[_LOGL_N];
static NMLogDomain logging[_LOGL_N_REAL];
static gboolean logging_set_up;
enum {
LOG_BACKEND_GLIB,
@@ -82,6 +82,7 @@ static const LogLevelDesc level_desc[_LOGL_N] = {
[LOGL_INFO] = { "INFO", "<info>", LOG_INFO, G_LOG_LEVEL_MESSAGE, FALSE },
[LOGL_WARN] = { "WARN", "<warn>", LOG_WARNING, G_LOG_LEVEL_WARNING, FALSE },
[LOGL_ERR] = { "ERR", "<error>", LOG_ERR, G_LOG_LEVEL_WARNING, TRUE },
[_LOGL_OFF] = { "OFF", NULL, 0, 0, FALSE },
};
static const LogDesc domain_descs[] = {
@@ -253,10 +254,12 @@ nm_logging_setup (const char *level,
continue;
}
for (i = 0; i < domain_log_level; i++)
new_logging[i] &= ~bits;
for (i = domain_log_level; i < _LOGL_N; i++)
new_logging[i] |= bits;
for (i = 0; i < G_N_ELEMENTS (new_logging); i++) {
if (i < domain_log_level)
new_logging[i] &= ~bits;
else
new_logging[i] |= bits;
}
}
g_strfreev (tmp);

View File

@@ -90,7 +90,11 @@ typedef enum { /*< skip >*/
LOGL_WARN,
LOGL_ERR,
_LOGL_N, /* the number of logging levels */
_LOGL_N_REAL, /* the number of actual logging levels */
_LOGL_OFF = _LOGL_N_REAL, /* special logging level that is always disabled. */
_LOGL_N, /* the number of logging levels including "OFF" */
} NMLogLevel;
#define nm_log_err(domain, ...) nm_log (LOGL_ERR, (domain), __VA_ARGS__)