2008-11-03 04:13:42 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2006-02-27 04:31:52 +00:00
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
2008-06-26 18:31:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-02-27 04:31:52 +00:00
|
|
|
*
|
2012-10-31 17:19:38 +01:00
|
|
|
* Copyright (C) 2006 - 2012 Red Hat, Inc.
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2006 - 2008 Novell, Inc.
|
2006-02-27 04:31:52 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2011-03-14 01:00:56 -05:00
|
|
|
|
2009-08-21 12:16:17 -05:00
|
|
|
#include <dlfcn.h>
|
2006-02-27 04:31:52 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <sys/stat.h>
|
2010-04-06 15:23:08 -07:00
|
|
|
#include <strings.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2016-03-01 08:56:14 +01:00
|
|
|
#if defined (NO_SYSTEMD_JOURNAL) && defined (SYSTEMD_JOURNAL)
|
|
|
|
|
#undef SYSTEMD_JOURNAL
|
|
|
|
|
#define SYSTEMD_JOURNAL 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
#define SD_JOURNAL_SUPPRESS_LOCATION
|
|
|
|
|
#include <systemd/sd-journal.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-16 16:47:30 -04:00
|
|
|
#include "nm-errors.h"
|
2016-03-01 09:56:51 +01:00
|
|
|
#include "nm-core-utils.h"
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2016-02-13 16:27:11 +01:00
|
|
|
typedef enum {
|
|
|
|
|
LOG_FORMAT_FLAG_NONE = 0,
|
|
|
|
|
LOG_FORMAT_FLAG_TIMESTAMP_DEBUG = (1LL << 0),
|
|
|
|
|
LOG_FORMAT_FLAG_TIMESTAMP_INFO = (1LL << 1),
|
|
|
|
|
LOG_FORMAT_FLAG_TIMESTAMP_ERROR = (1LL << 2),
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_DEBUG = (1LL << 3),
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_INFO = (1LL << 4),
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_ERROR = (1LL << 5),
|
2016-02-13 17:50:07 +01:00
|
|
|
LOG_FORMAT_FLAG_ALIGN_LOCATION = (1LL << 6),
|
2016-02-13 16:27:11 +01:00
|
|
|
|
|
|
|
|
_LOG_FORMAT_FLAG_TIMESTAMP = LOG_FORMAT_FLAG_TIMESTAMP_DEBUG |
|
|
|
|
|
LOG_FORMAT_FLAG_TIMESTAMP_INFO |
|
|
|
|
|
LOG_FORMAT_FLAG_TIMESTAMP_ERROR,
|
|
|
|
|
_LOG_FORMAT_FLAG_LOCATION = LOG_FORMAT_FLAG_LOCATION_DEBUG |
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_INFO |
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_ERROR,
|
|
|
|
|
|
|
|
|
|
_LOG_FORMAT_FLAG_LEVEL_DEBUG = LOG_FORMAT_FLAG_TIMESTAMP_DEBUG |
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_DEBUG,
|
|
|
|
|
_LOG_FORMAT_FLAG_LEVEL_INFO = LOG_FORMAT_FLAG_TIMESTAMP_INFO |
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_INFO,
|
|
|
|
|
_LOG_FORMAT_FLAG_LEVEL_ERROR = LOG_FORMAT_FLAG_TIMESTAMP_ERROR |
|
|
|
|
|
LOG_FORMAT_FLAG_LOCATION_ERROR,
|
|
|
|
|
|
2016-02-13 19:23:44 +01:00
|
|
|
_LOG_FORMAT_FLAG_SYSLOG = _LOG_FORMAT_FLAG_TIMESTAMP |
|
2016-02-13 16:27:11 +01:00
|
|
|
LOG_FORMAT_FLAG_LOCATION_DEBUG |
|
2016-02-13 19:23:44 +01:00
|
|
|
LOG_FORMAT_FLAG_LOCATION_ERROR |
|
|
|
|
|
LOG_FORMAT_FLAG_ALIGN_LOCATION,
|
logging: change logging format to drop "[file:line] func():" part
Choose a new logging format.
- the logging format must not be configurable and it must be the
same for all backends. It is neat that journal supports additional
fields, but an average user still posts the output of plain
journalctl, without "--output verbose" (which would also be hard
to read).
Also, we get used to a certain logging format, so having different
formats is confusing. If one format is better then another, it should
be used for all backends: syslog, journal and debug.
The only question is, what is the best format.
- the timestamp: I find it useful to see how much time between two
events passed. The timestamp printed by syslog doesn't have sufficient
granularity, and the internal journal fields are not readily available.
We used to print the timestamps for <error>, <debug> and <trace>,
but ommited them for <info> and <warn> levels. We now print them for
all levels, which has a uniform alignment.
- the location: the "[file:line] func():" part is mostly redundant
and results in wide lines. It also causes a misalignment of the
logging lines, or -- as I recently added alignment of the location --
it results in awkward whitespace and truncation.
But the location is really just necessary because our logging messages
are bad:
"<debug> [1456397604.038226] (9) 11-dhclient succeeded"
The solution to this is not
"<debug> [1456397604.038226] [nm-dispatcher.c:358] dispatcher_results_process(): (9) 11-dhclient succeeded"
but a properly worded message:
"<debug> [1456397604.038226] dispatcher: request #9, script 11-dhclient succeeded"
- logging-message: we need to write better logging messages.
I like some form of "tags" that are easy to grep:
"platform: signal: link changed: 4: ..."
Downside is, that this is not nice to read as a full sentence.
So, especially for <info> and <warn> logging, more human readable
messages are better.
We should find a compromise, where the log message explains what
happens, but is still concise and contains patterns that are easy
to grep and identify visually.
https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00077.html
2016-02-25 17:21:29 +01:00
|
|
|
|
|
|
|
|
_LOG_FORMAT_FLAG_DEFAULT = _LOG_FORMAT_FLAG_TIMESTAMP,
|
2016-02-13 16:27:11 +01:00
|
|
|
} LogFormatFlags;
|
|
|
|
|
|
2016-03-01 10:17:44 +01:00
|
|
|
void (*_nm_logging_clear_platform_logging_cache) (void);
|
|
|
|
|
|
2013-06-14 14:51:04 -04:00
|
|
|
static void
|
|
|
|
|
nm_log_handler (const gchar *log_domain,
|
|
|
|
|
GLogLevelFlags level,
|
|
|
|
|
const gchar *message,
|
|
|
|
|
gpointer ignored);
|
|
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
typedef struct {
|
2014-10-30 12:44:36 +01:00
|
|
|
NMLogDomain num;
|
2010-04-06 15:23:08 -07:00
|
|
|
const char *name;
|
|
|
|
|
} LogDesc;
|
|
|
|
|
|
2015-07-09 13:55:51 +02:00
|
|
|
typedef struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *level_str;
|
2016-05-24 19:46:33 +02:00
|
|
|
|
|
|
|
|
/* nm-logging uses syslog internally. Note that the three most-verbose syslog levels
|
|
|
|
|
* are LOG_DEBUG, LOG_INFO and LOG_NOTICE. Journal already highlights LOG_NOTICE
|
|
|
|
|
* as special.
|
|
|
|
|
*
|
|
|
|
|
* On the other hand, we have three levels LOGL_TRACE, LOGL_DEBUG and LOGL_INFO,
|
|
|
|
|
* which are regular messages not to be highlighted. For that reason, we must map
|
|
|
|
|
* LOGL_TRACE and LOGL_DEBUG both to syslog level LOG_DEBUG. */
|
2015-07-09 13:55:51 +02:00
|
|
|
int syslog_level;
|
2016-05-24 19:46:33 +02:00
|
|
|
|
2015-07-09 13:55:51 +02:00
|
|
|
GLogLevelFlags g_log_level;
|
2016-02-13 16:27:11 +01:00
|
|
|
LogFormatFlags log_format_level;
|
2015-07-09 13:55:51 +02:00
|
|
|
} LogLevelDesc;
|
|
|
|
|
|
2016-05-19 19:05:43 +02:00
|
|
|
NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL] = {
|
2016-06-16 22:30:41 +02:00
|
|
|
/* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL);
|
|
|
|
|
*
|
|
|
|
|
* Note: LOGD_VPN_PLUGIN is special and must be disabled for
|
|
|
|
|
* DEBUG and TRACE levels. */
|
2016-05-19 19:01:58 +02:00
|
|
|
[LOGL_INFO] = LOGD_DEFAULT,
|
|
|
|
|
[LOGL_WARN] = LOGD_DEFAULT,
|
|
|
|
|
[LOGL_ERR] = LOGD_DEFAULT,
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
static struct {
|
|
|
|
|
NMLogLevel log_level;
|
2016-02-13 16:27:11 +01:00
|
|
|
LogFormatFlags log_format_flags;
|
2016-05-23 12:02:31 +02:00
|
|
|
bool uses_syslog:1;
|
2015-10-07 11:07:09 +02:00
|
|
|
enum {
|
|
|
|
|
LOG_BACKEND_GLIB,
|
|
|
|
|
LOG_BACKEND_SYSLOG,
|
|
|
|
|
LOG_BACKEND_JOURNAL,
|
|
|
|
|
} log_backend;
|
|
|
|
|
char *logging_domains_to_string;
|
|
|
|
|
const LogLevelDesc level_desc[_LOGL_N];
|
|
|
|
|
|
2016-05-17 19:29:38 +02:00
|
|
|
#define _DOMAIN_DESC_LEN 38
|
2015-10-07 11:07:09 +02:00
|
|
|
/* Would be nice to use C99 flexible array member here,
|
|
|
|
|
* but that feature doesn't seem well supported. */
|
|
|
|
|
const LogDesc domain_desc[_DOMAIN_DESC_LEN];
|
|
|
|
|
} global = {
|
2016-05-19 18:57:18 +02:00
|
|
|
/* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); */
|
2015-10-07 11:07:09 +02:00
|
|
|
.log_level = LOGL_INFO,
|
|
|
|
|
.log_backend = LOG_BACKEND_GLIB,
|
logging: change logging format to drop "[file:line] func():" part
Choose a new logging format.
- the logging format must not be configurable and it must be the
same for all backends. It is neat that journal supports additional
fields, but an average user still posts the output of plain
journalctl, without "--output verbose" (which would also be hard
to read).
Also, we get used to a certain logging format, so having different
formats is confusing. If one format is better then another, it should
be used for all backends: syslog, journal and debug.
The only question is, what is the best format.
- the timestamp: I find it useful to see how much time between two
events passed. The timestamp printed by syslog doesn't have sufficient
granularity, and the internal journal fields are not readily available.
We used to print the timestamps for <error>, <debug> and <trace>,
but ommited them for <info> and <warn> levels. We now print them for
all levels, which has a uniform alignment.
- the location: the "[file:line] func():" part is mostly redundant
and results in wide lines. It also causes a misalignment of the
logging lines, or -- as I recently added alignment of the location --
it results in awkward whitespace and truncation.
But the location is really just necessary because our logging messages
are bad:
"<debug> [1456397604.038226] (9) 11-dhclient succeeded"
The solution to this is not
"<debug> [1456397604.038226] [nm-dispatcher.c:358] dispatcher_results_process(): (9) 11-dhclient succeeded"
but a properly worded message:
"<debug> [1456397604.038226] dispatcher: request #9, script 11-dhclient succeeded"
- logging-message: we need to write better logging messages.
I like some form of "tags" that are easy to grep:
"platform: signal: link changed: 4: ..."
Downside is, that this is not nice to read as a full sentence.
So, especially for <info> and <warn> logging, more human readable
messages are better.
We should find a compromise, where the log message explains what
happens, but is still concise and contains patterns that are easy
to grep and identify visually.
https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00077.html
2016-02-25 17:21:29 +01:00
|
|
|
.log_format_flags = _LOG_FORMAT_FLAG_DEFAULT,
|
2015-10-07 11:07:09 +02:00
|
|
|
.level_desc = {
|
2016-02-13 16:27:11 +01:00
|
|
|
[LOGL_TRACE] = { "TRACE", "<trace>", LOG_DEBUG, G_LOG_LEVEL_DEBUG, _LOG_FORMAT_FLAG_LEVEL_DEBUG },
|
2016-05-24 19:46:33 +02:00
|
|
|
[LOGL_DEBUG] = { "DEBUG", "<debug>", LOG_DEBUG, G_LOG_LEVEL_DEBUG, _LOG_FORMAT_FLAG_LEVEL_DEBUG },
|
2016-03-10 11:15:32 +01:00
|
|
|
[LOGL_INFO] = { "INFO", "<info>", LOG_INFO, G_LOG_LEVEL_INFO, _LOG_FORMAT_FLAG_LEVEL_INFO },
|
|
|
|
|
[LOGL_WARN] = { "WARN", "<warn>", LOG_WARNING, G_LOG_LEVEL_MESSAGE, _LOG_FORMAT_FLAG_LEVEL_INFO },
|
|
|
|
|
[LOGL_ERR] = { "ERR", "<error>", LOG_ERR, G_LOG_LEVEL_MESSAGE, _LOG_FORMAT_FLAG_LEVEL_ERROR },
|
2016-02-13 16:27:11 +01:00
|
|
|
[_LOGL_OFF] = { "OFF", NULL, 0, 0, 0 },
|
|
|
|
|
[_LOGL_KEEP] = { "KEEP", NULL, 0, 0, 0 },
|
2015-10-07 11:07:09 +02:00
|
|
|
},
|
|
|
|
|
.domain_desc = {
|
|
|
|
|
{ LOGD_PLATFORM, "PLATFORM" },
|
|
|
|
|
{ LOGD_RFKILL, "RFKILL" },
|
|
|
|
|
{ LOGD_ETHER, "ETHER" },
|
|
|
|
|
{ LOGD_WIFI, "WIFI" },
|
|
|
|
|
{ LOGD_BT, "BT" },
|
|
|
|
|
{ LOGD_MB, "MB" },
|
|
|
|
|
{ LOGD_DHCP4, "DHCP4" },
|
|
|
|
|
{ LOGD_DHCP6, "DHCP6" },
|
|
|
|
|
{ LOGD_PPP, "PPP" },
|
|
|
|
|
{ LOGD_WIFI_SCAN, "WIFI_SCAN" },
|
|
|
|
|
{ LOGD_IP4, "IP4" },
|
|
|
|
|
{ LOGD_IP6, "IP6" },
|
|
|
|
|
{ LOGD_AUTOIP4, "AUTOIP4" },
|
|
|
|
|
{ LOGD_DNS, "DNS" },
|
|
|
|
|
{ LOGD_VPN, "VPN" },
|
|
|
|
|
{ LOGD_SHARING, "SHARING" },
|
|
|
|
|
{ LOGD_SUPPLICANT,"SUPPLICANT" },
|
|
|
|
|
{ LOGD_AGENTS, "AGENTS" },
|
|
|
|
|
{ LOGD_SETTINGS, "SETTINGS" },
|
|
|
|
|
{ LOGD_SUSPEND, "SUSPEND" },
|
|
|
|
|
{ LOGD_CORE, "CORE" },
|
|
|
|
|
{ LOGD_DEVICE, "DEVICE" },
|
|
|
|
|
{ LOGD_OLPC, "OLPC" },
|
|
|
|
|
{ LOGD_INFINIBAND,"INFINIBAND" },
|
|
|
|
|
{ LOGD_FIREWALL, "FIREWALL" },
|
|
|
|
|
{ LOGD_ADSL, "ADSL" },
|
|
|
|
|
{ LOGD_BOND, "BOND" },
|
|
|
|
|
{ LOGD_VLAN, "VLAN" },
|
|
|
|
|
{ LOGD_BRIDGE, "BRIDGE" },
|
|
|
|
|
{ LOGD_DBUS_PROPS,"DBUS_PROPS" },
|
|
|
|
|
{ LOGD_TEAM, "TEAM" },
|
|
|
|
|
{ LOGD_CONCHECK, "CONCHECK" },
|
|
|
|
|
{ LOGD_DCB, "DCB" },
|
|
|
|
|
{ LOGD_DISPATCH, "DISPATCH" },
|
|
|
|
|
{ LOGD_AUDIT, "AUDIT" },
|
2016-03-11 16:11:04 +01:00
|
|
|
{ LOGD_SYSTEMD, "SYSTEMD" },
|
2016-05-17 19:29:38 +02:00
|
|
|
{ LOGD_VPN_PLUGIN,"VPN_PLUGIN" },
|
2015-10-07 11:07:09 +02:00
|
|
|
{ 0, NULL }
|
|
|
|
|
/* keep _DOMAIN_DESC_LEN in sync */
|
|
|
|
|
},
|
2010-04-06 15:23:08 -07:00
|
|
|
};
|
|
|
|
|
|
2015-01-25 21:42:37 +01:00
|
|
|
/* We have more then 32 logging domains. Assert that it compiles to a 64 bit sized enum */
|
|
|
|
|
G_STATIC_ASSERT (sizeof (NMLogDomain) >= sizeof (guint64));
|
|
|
|
|
|
2012-10-31 17:19:38 +01:00
|
|
|
/* Combined domains */
|
2012-12-17 17:12:44 +01:00
|
|
|
#define LOGD_ALL_STRING "ALL"
|
|
|
|
|
#define LOGD_DEFAULT_STRING "DEFAULT"
|
|
|
|
|
#define LOGD_DHCP_STRING "DHCP"
|
|
|
|
|
#define LOGD_IP_STRING "IP"
|
2012-10-31 17:19:38 +01:00
|
|
|
|
2010-04-08 08:56:17 -07:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
static char *_domains_to_string (gboolean include_level_override);
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
static gboolean
|
|
|
|
|
match_log_level (const char *level,
|
2014-10-30 12:44:36 +01:00
|
|
|
NMLogLevel *out_level,
|
2013-10-01 11:40:22 -04:00
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (global.level_desc); i++) {
|
|
|
|
|
if (!g_ascii_strcasecmp (global.level_desc[i].name, level)) {
|
2013-10-01 11:40:22 -04:00
|
|
|
*out_level = i;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 16:47:30 -04:00
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_LEVEL,
|
2013-10-01 11:40:22 -04:00
|
|
|
_("Unknown log level '%s'"), level);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
gboolean
|
2013-11-26 11:33:42 -05:00
|
|
|
nm_logging_setup (const char *level,
|
|
|
|
|
const char *domains,
|
|
|
|
|
char **bad_domains,
|
|
|
|
|
GError **error)
|
2010-04-06 15:23:08 -07:00
|
|
|
{
|
2013-11-26 11:33:42 -05:00
|
|
|
GString *unrecognized = NULL;
|
2016-05-19 19:01:58 +02:00
|
|
|
NMLogDomain new_logging[G_N_ELEMENTS (_nm_logging_enabled_state)];
|
2015-10-07 11:07:09 +02:00
|
|
|
NMLogLevel new_log_level = global.log_level;
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
char **tmp, **iter;
|
2013-10-01 11:40:22 -04:00
|
|
|
int i;
|
2015-10-06 19:48:35 +02:00
|
|
|
gboolean had_platform_debug;
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
gs_free char *domains_free = NULL;
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2014-02-12 11:05:02 +01:00
|
|
|
g_return_val_if_fail (!bad_domains || !*bad_domains, FALSE);
|
|
|
|
|
g_return_val_if_fail (!error || !*error, FALSE);
|
|
|
|
|
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
/* domains */
|
2016-05-19 18:57:18 +02:00
|
|
|
if (!domains || !*domains)
|
|
|
|
|
domains = (domains_free = _domains_to_string (FALSE));
|
2014-04-05 09:38:59 -04:00
|
|
|
|
2015-08-01 14:15:44 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2013-10-01 11:40:22 -04:00
|
|
|
new_logging[i] = 0;
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
/* levels */
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
if (level && *level) {
|
2013-10-01 11:40:22 -04:00
|
|
|
if (!match_log_level (level, &new_log_level, error))
|
2010-04-06 15:53:37 -07:00
|
|
|
return FALSE;
|
2015-10-07 10:45:28 +02:00
|
|
|
if (new_log_level == _LOGL_KEEP) {
|
2015-10-07 11:07:09 +02:00
|
|
|
new_log_level = global.log_level;
|
2015-10-07 10:45:28 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2016-05-19 19:01:58 +02:00
|
|
|
new_logging[i] = _nm_logging_enabled_state[i];
|
2015-10-07 10:45:28 +02:00
|
|
|
}
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
tmp = g_strsplit_set (domains, ", ", 0);
|
|
|
|
|
for (iter = tmp; iter && *iter; iter++) {
|
|
|
|
|
const LogDesc *diter;
|
2014-10-30 12:44:36 +01:00
|
|
|
NMLogLevel domain_log_level;
|
|
|
|
|
NMLogDomain bits;
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
char *p;
|
|
|
|
|
|
2016-06-16 22:30:41 +02:00
|
|
|
/* LOGD_VPN_PLUGIN is protected, that is, when setting ALL or DEFAULT,
|
|
|
|
|
* it does not enable the verbose levels DEBUG and TRACE, because that
|
|
|
|
|
* may expose sensitive data. */
|
|
|
|
|
NMLogDomain protect = LOGD_NONE;
|
|
|
|
|
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
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 */
|
2016-06-16 22:30:41 +02:00
|
|
|
if (!g_ascii_strcasecmp (*iter, LOGD_ALL_STRING)) {
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
bits = LOGD_ALL;
|
2016-06-16 22:30:41 +02:00
|
|
|
protect = LOGD_VPN_PLUGIN;
|
|
|
|
|
} else if (!g_ascii_strcasecmp (*iter, LOGD_DEFAULT_STRING)) {
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
bits = LOGD_DEFAULT;
|
2016-06-16 22:30:41 +02:00
|
|
|
protect = LOGD_VPN_PLUGIN;
|
|
|
|
|
} else if (!g_ascii_strcasecmp (*iter, LOGD_DHCP_STRING))
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
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;
|
wimax: drop WiMAX support (bgo #747846)
Even Fedora is no longer shipping the WiMAX SDK, so it's likely we'll
eventually accidentally break some of the code in src/devices/wimax/
(if we haven't already). Discussion on the list showed a consensus for
dropping support for WiMAX.
So, remove the SDK checks from configure.ac, remove the WiMAX device
plugin and associated manager support, and deprecate all the APIs.
For compatibility reasons, it is still possible to create and save
WiMAX connections, to toggle the software WiMAX rfkill state, and to
change the "WIMAX" log level, although none of these have any effect,
since no NMDeviceWimax will ever be created.
nmcli was only compiling in support for most WiMAX operations when NM
as a whole was built with WiMAX support, so that code has been removed
now as well. (It is still possible to use nmcli to create and edit
WiMAX connections, but those connections will never be activatable.)
2015-04-13 17:07:00 -04:00
|
|
|
else if (!g_ascii_strcasecmp (*iter, "WIMAX"))
|
|
|
|
|
continue;
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
|
|
|
|
|
else {
|
2015-10-07 11:07:09 +02:00
|
|
|
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
if (!g_ascii_strcasecmp (diter->name, *iter)) {
|
|
|
|
|
bits = diter->num;
|
|
|
|
|
break;
|
2013-11-26 11:33:42 -05:00
|
|
|
}
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
}
|
2013-11-26 11:33:42 -05:00
|
|
|
|
2015-08-01 14:35:51 +02:00
|
|
|
if (!bits) {
|
|
|
|
|
if (!bad_domains) {
|
|
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN,
|
|
|
|
|
_("Unknown log domain '%s'"), *iter);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-08-01 14:35:51 +02:00
|
|
|
if (unrecognized)
|
|
|
|
|
g_string_append (unrecognized, ", ");
|
|
|
|
|
else
|
|
|
|
|
unrecognized = g_string_new (NULL);
|
|
|
|
|
g_string_append (unrecognized, *iter);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-10-07 10:45:28 +02:00
|
|
|
if (domain_log_level == _LOGL_KEEP) {
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2016-05-19 19:01:58 +02:00
|
|
|
new_logging[i] = (new_logging[i] & ~bits) | (_nm_logging_enabled_state[i] & bits);
|
2015-10-07 10:45:28 +02:00
|
|
|
} else {
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++) {
|
|
|
|
|
if (i < domain_log_level)
|
|
|
|
|
new_logging[i] &= ~bits;
|
2016-06-16 22:30:41 +02:00
|
|
|
else {
|
2015-10-07 10:45:28 +02:00
|
|
|
new_logging[i] |= bits;
|
2016-06-16 22:30:41 +02:00
|
|
|
if ( protect
|
|
|
|
|
&& i < LOGL_INFO)
|
|
|
|
|
new_logging[i] &= ~protect;
|
|
|
|
|
}
|
2015-10-07 10:45:28 +02:00
|
|
|
}
|
2015-08-01 14:12:34 +02:00
|
|
|
}
|
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...
2014-01-21 09:54:50 -05:00
|
|
|
}
|
|
|
|
|
g_strfreev (tmp);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
g_clear_pointer (&global.logging_domains_to_string, g_free);
|
2014-02-12 11:30:29 +01:00
|
|
|
|
2015-10-06 19:48:35 +02:00
|
|
|
had_platform_debug = nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM);
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
global.log_level = new_log_level;
|
2015-08-01 14:15:44 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2016-05-19 19:01:58 +02:00
|
|
|
_nm_logging_enabled_state[i] = new_logging[i];
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-10-06 19:48:35 +02:00
|
|
|
if ( had_platform_debug
|
2016-03-01 10:17:44 +01:00
|
|
|
&& _nm_logging_clear_platform_logging_cache
|
2015-10-06 19:48:35 +02:00
|
|
|
&& !nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
|
|
|
|
|
/* when debug logging is enabled, platform will cache all access to
|
|
|
|
|
* sysctl. When the user disables debug-logging, we want to clear that
|
|
|
|
|
* cache right away. */
|
2016-03-01 10:17:44 +01:00
|
|
|
_nm_logging_clear_platform_logging_cache ();
|
2015-10-06 19:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-26 11:33:42 -05:00
|
|
|
if (unrecognized)
|
|
|
|
|
*bad_domains = g_string_free (unrecognized, FALSE);
|
|
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 11:17:26 +01:00
|
|
|
const char *
|
2010-05-04 12:06:00 -07:00
|
|
|
nm_logging_level_to_string (void)
|
|
|
|
|
{
|
2015-10-07 11:07:09 +02:00
|
|
|
return global.level_desc[global.log_level].name;
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
|
|
|
|
|
2013-03-11 12:23:57 -04:00
|
|
|
const char *
|
|
|
|
|
nm_logging_all_levels_to_string (void)
|
|
|
|
|
{
|
|
|
|
|
static GString *str;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!str)) {
|
2013-10-01 11:40:22 -04:00
|
|
|
int i;
|
2013-03-11 12:23:57 -04:00
|
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
2015-10-07 11:07:09 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (global.level_desc); i++) {
|
2013-03-11 12:23:57 -04:00
|
|
|
if (str->len)
|
|
|
|
|
g_string_append_c (str, ',');
|
2015-10-07 11:07:09 +02:00
|
|
|
g_string_append (str, global.level_desc[i].name);
|
2013-03-11 12:23:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str->str;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
const char *
|
2010-05-04 12:06:00 -07:00
|
|
|
nm_logging_domains_to_string (void)
|
|
|
|
|
{
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
if (G_UNLIKELY (!global.logging_domains_to_string))
|
|
|
|
|
global.logging_domains_to_string = _domains_to_string (TRUE);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
return global.logging_domains_to_string;
|
|
|
|
|
}
|
2010-05-04 12:06:00 -07:00
|
|
|
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
static char *
|
|
|
|
|
_domains_to_string (gboolean include_level_override)
|
|
|
|
|
{
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
GString *str;
|
|
|
|
|
int i;
|
2013-10-01 11:40:22 -04:00
|
|
|
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
/* We don't just return g_strdup (global.log_domains) because we want to expand
|
|
|
|
|
* "DEFAULT" and "ALL".
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
str = g_string_sized_new (75);
|
|
|
|
|
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
|
|
|
|
/* If it's set for any lower level, it will also be set for LOGL_ERR */
|
2016-05-19 19:01:58 +02:00
|
|
|
if (!(diter->num & _nm_logging_enabled_state[LOGL_ERR]))
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (str->len)
|
|
|
|
|
g_string_append_c (str, ',');
|
|
|
|
|
g_string_append (str, diter->name);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
if (!include_level_override)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Check if it's logging at a lower level than the default. */
|
|
|
|
|
for (i = 0; i < global.log_level; i++) {
|
2016-05-19 19:01:58 +02:00
|
|
|
if (diter->num & _nm_logging_enabled_state[i]) {
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
g_string_append_printf (str, ":%s", global.level_desc[i].name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Check if it's logging at a higher level than the default. */
|
2016-05-19 19:01:58 +02:00
|
|
|
if (!(diter->num & _nm_logging_enabled_state[global.log_level])) {
|
|
|
|
|
for (i = global.log_level + 1; i < G_N_ELEMENTS (_nm_logging_enabled_state); i++) {
|
|
|
|
|
if (diter->num & _nm_logging_enabled_state[i]) {
|
2015-10-07 11:07:09 +02:00
|
|
|
g_string_append_printf (str, ":%s", global.level_desc[i].name);
|
2013-10-01 11:40:22 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:
(1) $ nmcli g l level INFO domains DNS,CORE
$ nmcli g l
LEVEL DOMAINS
INFO DNS,CORE
(2) $ nmcli g l level KEEP domains PPP:TRACE
$ nmcli g l
LEVEL DOMAINS
INFO PPP:TRACE,DNS,CORE
(3) $ nmcli g l level ERR
$ nmcli g l
LEVEL DOMAINS
ERR PPP:TRACE
with this change, command (3) effectively translates to:
$ nmcli g l level ERR domains PPP,DNS,CORE
$ nmcli g l
LEVEL DOMAINS
ERR PPP,DNS,CORE
2015-10-09 12:36:29 +02:00
|
|
|
return g_string_free (str, FALSE);
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
|
|
|
|
|
2013-03-11 12:23:57 -04:00
|
|
|
const char *
|
|
|
|
|
nm_logging_all_domains_to_string (void)
|
|
|
|
|
{
|
|
|
|
|
static GString *str;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!str)) {
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
|
2013-07-27 12:43:53 +02:00
|
|
|
str = g_string_new (LOGD_DEFAULT_STRING);
|
2015-10-07 11:07:09 +02:00
|
|
|
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
2013-03-11 12:23:57 -04:00
|
|
|
g_string_append_c (str, ',');
|
|
|
|
|
g_string_append (str, diter->name);
|
|
|
|
|
if (diter->num == LOGD_DHCP6)
|
2013-07-27 12:43:53 +02:00
|
|
|
g_string_append (str, "," LOGD_DHCP_STRING);
|
2013-03-11 12:23:57 -04:00
|
|
|
else if (diter->num == LOGD_IP6)
|
2013-07-27 12:43:53 +02:00
|
|
|
g_string_append (str, "," LOGD_IP_STRING);
|
2013-03-11 12:23:57 -04:00
|
|
|
}
|
2013-07-27 12:43:53 +02:00
|
|
|
g_string_append (str, "," LOGD_ALL_STRING);
|
2013-03-11 12:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str->str;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 10:56:27 +02:00
|
|
|
/**
|
|
|
|
|
* nm_logging_get_level:
|
|
|
|
|
* @domain: find the lowest enabled logging level for the
|
|
|
|
|
* given domain. If this is a set of multiple
|
|
|
|
|
* domains, the most verbose level will be returned.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the lowest (most verbose) logging level for the
|
|
|
|
|
* give @domain, or %_LOGL_OFF if it is disabled.
|
|
|
|
|
**/
|
|
|
|
|
NMLogLevel
|
|
|
|
|
nm_logging_get_level (NMLogDomain domain)
|
|
|
|
|
{
|
|
|
|
|
NMLogLevel sl = _LOGL_OFF;
|
|
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (LOGL_TRACE == 0);
|
|
|
|
|
while ( sl > LOGL_TRACE
|
|
|
|
|
&& nm_logging_enabled (sl - 1, domain))
|
|
|
|
|
sl--;
|
|
|
|
|
return sl;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
2016-06-05 12:21:48 +02:00
|
|
|
_nm_printf (4, 5)
|
2015-07-08 16:21:21 +02:00
|
|
|
static void
|
|
|
|
|
_iovec_set_format (struct iovec *iov, gboolean *iov_free, int i, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
va_start (ap, format);
|
|
|
|
|
str = g_strdup_vprintf (format, ap);
|
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
|
|
iov[i].iov_base = str;
|
|
|
|
|
iov[i].iov_len = strlen (str);
|
|
|
|
|
iov_free[i] = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_iovec_set_string (struct iovec *iov, gboolean *iov_free, int i, const char *str, gsize len)
|
|
|
|
|
{
|
|
|
|
|
iov[i].iov_base = (char *) str;
|
|
|
|
|
iov[i].iov_len = len;
|
|
|
|
|
iov_free[i] = FALSE;
|
|
|
|
|
}
|
2016-02-12 12:34:43 +01:00
|
|
|
#define _iovec_set_literal_string(iov, iov_free, i, str) _iovec_set_string ((iov), (iov_free), (i), (""str""), NM_STRLEN (str))
|
2015-07-08 16:21:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
2011-03-19 12:42:29 -05:00
|
|
|
void
|
2015-04-22 11:06:49 +02:00
|
|
|
_nm_log_impl (const char *file,
|
|
|
|
|
guint line,
|
|
|
|
|
const char *func,
|
|
|
|
|
NMLogLevel level,
|
|
|
|
|
NMLogDomain domain,
|
|
|
|
|
int error,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
2010-04-06 15:23:08 -07:00
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
char *msg;
|
2016-02-13 16:27:11 +01:00
|
|
|
char *fullmsg;
|
|
|
|
|
char s_buf_timestamp[64];
|
|
|
|
|
char s_buf_location[1024];
|
2010-04-06 15:23:08 -07:00
|
|
|
GTimeVal tv;
|
|
|
|
|
|
2016-05-19 19:01:58 +02:00
|
|
|
if ((guint) level >= G_N_ELEMENTS (_nm_logging_enabled_state))
|
2015-07-08 16:21:21 +02:00
|
|
|
g_return_if_reached ();
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2016-05-19 19:01:58 +02:00
|
|
|
if (!(_nm_logging_enabled_state[level] & domain))
|
2010-04-06 15:23:08 -07:00
|
|
|
return;
|
|
|
|
|
|
2014-12-05 00:54:30 +01:00
|
|
|
/* Make sure that %m maps to the specified error */
|
2015-09-23 16:03:41 +02:00
|
|
|
if (error != 0) {
|
|
|
|
|
if (error < 0)
|
|
|
|
|
error = -error;
|
2014-12-05 00:54:30 +01:00
|
|
|
errno = error;
|
2015-09-23 16:03:41 +02:00
|
|
|
}
|
2014-12-05 00:54:30 +01:00
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
va_start (args, fmt);
|
|
|
|
|
msg = g_strdup_vprintf (fmt, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2016-02-13 16:27:11 +01:00
|
|
|
if (NM_FLAGS_ANY (global.log_format_flags, global.level_desc[level].log_format_level & _LOG_FORMAT_FLAG_TIMESTAMP)) {
|
|
|
|
|
g_get_current_time (&tv);
|
2016-03-01 15:20:31 +01:00
|
|
|
nm_sprintf_buf (s_buf_timestamp, " [%ld.%04ld]", tv.tv_sec, (tv.tv_usec + 50) / 100);
|
2016-02-13 16:27:11 +01:00
|
|
|
} else
|
|
|
|
|
s_buf_timestamp[0] = '\0';
|
|
|
|
|
|
|
|
|
|
s_buf_location[0] = '\0';
|
|
|
|
|
if (NM_FLAGS_ANY (global.log_format_flags, global.level_desc[level].log_format_level & _LOG_FORMAT_FLAG_LOCATION)) {
|
2016-02-13 17:50:07 +01:00
|
|
|
#define MAX_LEN_FILE 37
|
|
|
|
|
#define MAX_LEN_FUNC 26
|
2016-02-13 16:27:11 +01:00
|
|
|
gsize l = sizeof (s_buf_location);
|
2016-02-13 17:50:07 +01:00
|
|
|
char *p = s_buf_location, *p_buf;
|
|
|
|
|
gsize len;
|
|
|
|
|
char s_buf[MAX (MAX_LEN_FILE, MAX_LEN_FUNC) + 30];
|
|
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
|
if (NM_FLAGS_HAS (global.log_format_flags, LOG_FORMAT_FLAG_ALIGN_LOCATION)) {
|
|
|
|
|
/* left-align the "[file:line]" string, but truncate from left to MAX_LEN_FILE chars. */
|
|
|
|
|
len = strlen (file);
|
|
|
|
|
nm_sprintf_buf (s_buf, "[%s:%u]",
|
|
|
|
|
len > MAX_LEN_FILE ? &file[len - MAX_LEN_FILE] : file,
|
|
|
|
|
line);
|
|
|
|
|
len = strlen (s_buf);
|
|
|
|
|
if (len > MAX_LEN_FILE) {
|
|
|
|
|
p_buf = &s_buf[len - MAX_LEN_FILE];
|
|
|
|
|
p_buf[0] = '[';
|
|
|
|
|
} else
|
|
|
|
|
p_buf = s_buf;
|
|
|
|
|
nm_utils_strbuf_append (&p, &l, " %-"G_STRINGIFY (MAX_LEN_FILE)"s", p_buf);
|
|
|
|
|
} else
|
|
|
|
|
nm_utils_strbuf_append (&p, &l, " [%s:%u]", file, line);
|
|
|
|
|
}
|
|
|
|
|
if (func) {
|
|
|
|
|
if (NM_FLAGS_HAS (global.log_format_flags, LOG_FORMAT_FLAG_ALIGN_LOCATION)) {
|
|
|
|
|
/* left-align the "func():" string, but truncate from left to MAX_LEN_FUNC chars. */
|
|
|
|
|
len = strlen (func);
|
|
|
|
|
nm_sprintf_buf (s_buf, "%s():",
|
|
|
|
|
len > MAX_LEN_FUNC ? &func[len - MAX_LEN_FUNC] : func);
|
|
|
|
|
len = strlen (s_buf);
|
|
|
|
|
nm_utils_strbuf_append (&p, &l, " %-"G_STRINGIFY (MAX_LEN_FUNC)"s",
|
|
|
|
|
len > MAX_LEN_FUNC ? &s_buf[len - MAX_LEN_FUNC] : s_buf);
|
|
|
|
|
} else
|
|
|
|
|
nm_utils_strbuf_append (&p, &l, " %s():", func);
|
|
|
|
|
}
|
2016-02-13 16:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
switch (global.log_backend) {
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
case LOG_BACKEND_JOURNAL:
|
|
|
|
|
{
|
|
|
|
|
gint64 now, boottime;
|
|
|
|
|
#define _NUM_MAX_FIELDS_SYSLOG_FACILITY 10
|
|
|
|
|
#define _NUM_FIELDS (10 + _NUM_MAX_FIELDS_SYSLOG_FACILITY)
|
|
|
|
|
int i_field = 0;
|
|
|
|
|
struct iovec iov[_NUM_FIELDS];
|
|
|
|
|
gboolean iov_free[_NUM_FIELDS];
|
|
|
|
|
|
|
|
|
|
now = nm_utils_get_monotonic_timestamp_ns ();
|
|
|
|
|
boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1);
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "PRIORITY=%d", global.level_desc[level].syslog_level);
|
2016-02-13 16:27:11 +01:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "MESSAGE="
|
|
|
|
|
"%-7s%s%s %s",
|
|
|
|
|
global.level_desc[level].level_str,
|
|
|
|
|
s_buf_timestamp,
|
|
|
|
|
s_buf_location,
|
|
|
|
|
msg);
|
2015-07-08 16:21:21 +02:00
|
|
|
_iovec_set_literal_string (iov, iov_free, i_field++, "SYSLOG_IDENTIFIER=" G_LOG_DOMAIN);
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "SYSLOG_PID=%ld", (long) getpid ());
|
|
|
|
|
{
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
int i_domain = _NUM_MAX_FIELDS_SYSLOG_FACILITY;
|
|
|
|
|
const char *s_domain_1 = NULL;
|
|
|
|
|
GString *s_domain_all = NULL;
|
|
|
|
|
NMLogDomain dom_all = domain;
|
2016-05-19 19:01:58 +02:00
|
|
|
NMLogDomain dom = dom_all & _nm_logging_enabled_state[level];
|
2015-07-08 16:21:21 +02:00
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
2015-07-08 16:21:21 +02:00
|
|
|
if (!NM_FLAGS_HAS (dom_all, diter->num))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* construct a list of all domains (not only the enabled ones).
|
|
|
|
|
* Note that in by far most cases, there is only one domain present.
|
|
|
|
|
* Hence, save the construction of the GString. */
|
|
|
|
|
dom_all &= ~diter->num;
|
|
|
|
|
if (!s_domain_1)
|
|
|
|
|
s_domain_1 = diter->name;
|
|
|
|
|
else {
|
|
|
|
|
if (!s_domain_all)
|
|
|
|
|
s_domain_all = g_string_new (s_domain_1);
|
|
|
|
|
g_string_append_c (s_domain_all, ',');
|
|
|
|
|
g_string_append (s_domain_all, diter->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NM_FLAGS_HAS (dom, diter->num)) {
|
|
|
|
|
if (i_domain > 0) {
|
|
|
|
|
/* SYSLOG_FACILITY is specified multiple times for each domain that is actually enabled. */
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "SYSLOG_FACILITY=%s", diter->name);
|
|
|
|
|
i_domain--;
|
|
|
|
|
}
|
|
|
|
|
dom &= ~diter->num;
|
|
|
|
|
}
|
|
|
|
|
if (!dom && !dom_all)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (s_domain_all) {
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "NM_LOG_DOMAINS=%s", s_domain_all->str);
|
|
|
|
|
g_string_free (s_domain_all, TRUE);
|
|
|
|
|
} else
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "NM_LOG_DOMAINS=%s", s_domain_1);
|
|
|
|
|
}
|
2015-10-07 11:07:09 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "NM_LOG_LEVEL=%s", global.level_desc[level].name);
|
2016-02-13 16:27:11 +01:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "CODE_FUNC=%s", func ?: "");
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "CODE_FILE=%s", file ?: "");
|
2015-07-08 16:21:21 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "CODE_LINE=%u", line);
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000));
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000));
|
|
|
|
|
if (error != 0)
|
|
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "ERRNO=%d", error);
|
|
|
|
|
|
|
|
|
|
nm_assert (i_field <= G_N_ELEMENTS (iov));
|
|
|
|
|
|
|
|
|
|
sd_journal_sendv (iov, i_field);
|
|
|
|
|
|
|
|
|
|
for (; i_field > 0; ) {
|
|
|
|
|
i_field--;
|
|
|
|
|
if (iov_free[i_field])
|
|
|
|
|
g_free (iov[i_field].iov_base);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-08 17:13:59 +02:00
|
|
|
break;
|
2015-07-08 16:21:21 +02:00
|
|
|
#endif
|
2015-07-08 17:13:59 +02:00
|
|
|
default:
|
2016-02-13 16:27:11 +01:00
|
|
|
fullmsg = g_strdup_printf ("%-7s%s%s %s",
|
|
|
|
|
global.level_desc[level].level_str,
|
|
|
|
|
s_buf_timestamp,
|
|
|
|
|
s_buf_location,
|
|
|
|
|
msg);
|
2015-07-08 16:21:21 +02:00
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
if (global.log_backend == LOG_BACKEND_SYSLOG)
|
|
|
|
|
syslog (global.level_desc[level].syslog_level, "%s", fullmsg);
|
2015-07-08 16:21:21 +02:00
|
|
|
else
|
2015-10-07 11:07:09 +02:00
|
|
|
g_log (G_LOG_DOMAIN, global.level_desc[level].g_log_level, "%s", fullmsg);
|
2016-02-13 16:27:11 +01:00
|
|
|
g_free (fullmsg);
|
2015-07-08 16:21:21 +02:00
|
|
|
break;
|
2015-07-08 17:13:59 +02:00
|
|
|
}
|
2013-06-14 14:51:04 -04:00
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
g_free (msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
2006-02-27 04:31:52 +00:00
|
|
|
static void
|
2010-04-06 15:23:08 -07:00
|
|
|
nm_log_handler (const gchar *log_domain,
|
|
|
|
|
GLogLevelFlags level,
|
|
|
|
|
const gchar *message,
|
|
|
|
|
gpointer ignored)
|
2006-02-27 04:31:52 +00:00
|
|
|
{
|
2015-07-08 16:21:21 +02:00
|
|
|
int syslog_priority;
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2014-04-24 20:01:13 +02:00
|
|
|
switch (level & G_LOG_LEVEL_MASK) {
|
2010-04-06 15:23:08 -07:00
|
|
|
case G_LOG_LEVEL_ERROR:
|
|
|
|
|
syslog_priority = LOG_CRIT;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_CRITICAL:
|
|
|
|
|
syslog_priority = LOG_ERR;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_WARNING:
|
|
|
|
|
syslog_priority = LOG_WARNING;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_MESSAGE:
|
|
|
|
|
syslog_priority = LOG_NOTICE;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_DEBUG:
|
|
|
|
|
syslog_priority = LOG_DEBUG;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_INFO:
|
|
|
|
|
default:
|
|
|
|
|
syslog_priority = LOG_INFO;
|
|
|
|
|
break;
|
2006-02-27 04:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
switch (global.log_backend) {
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
case LOG_BACKEND_JOURNAL:
|
|
|
|
|
{
|
|
|
|
|
gint64 now, boottime;
|
|
|
|
|
|
|
|
|
|
now = nm_utils_get_monotonic_timestamp_ns ();
|
|
|
|
|
boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1);
|
|
|
|
|
|
|
|
|
|
sd_journal_send ("PRIORITY=%d", syslog_priority,
|
2016-03-08 17:41:31 +01:00
|
|
|
"MESSAGE=%s", message ?: "",
|
2015-07-08 16:21:21 +02:00
|
|
|
"SYSLOG_IDENTIFIER=%s", G_LOG_DOMAIN,
|
|
|
|
|
"SYSLOG_PID=%ld", (long) getpid (),
|
|
|
|
|
"SYSLOG_FACILITY=GLIB",
|
2016-03-08 17:41:31 +01:00
|
|
|
"GLIB_DOMAIN=%s", log_domain ?: "",
|
2015-07-08 16:21:21 +02:00
|
|
|
"GLIB_LEVEL=%d", (int) (level & G_LOG_LEVEL_MASK),
|
|
|
|
|
"TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000),
|
|
|
|
|
"TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
2016-03-08 17:41:31 +01:00
|
|
|
syslog (syslog_priority, "%s", message ?: "");
|
2015-07-08 16:21:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2006-02-27 04:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-23 12:02:31 +02:00
|
|
|
gboolean
|
|
|
|
|
nm_logging_syslog_enabled (void)
|
|
|
|
|
{
|
|
|
|
|
return global.uses_syslog;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-27 04:31:52 +00:00
|
|
|
void
|
2015-07-08 19:34:34 +02:00
|
|
|
nm_logging_syslog_openlog (const char *logging_backend)
|
2006-02-27 04:31:52 +00:00
|
|
|
{
|
2016-02-13 16:27:11 +01:00
|
|
|
LogFormatFlags log_format_flags;
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
if (global.log_backend != LOG_BACKEND_GLIB)
|
2015-07-08 17:01:15 +02:00
|
|
|
g_return_if_reached ();
|
2015-07-08 17:13:59 +02:00
|
|
|
|
2015-07-08 21:44:01 +02:00
|
|
|
if (!logging_backend)
|
|
|
|
|
logging_backend = ""NM_CONFIG_LOGGING_BACKEND_DEFAULT;
|
|
|
|
|
|
logging: change logging format to drop "[file:line] func():" part
Choose a new logging format.
- the logging format must not be configurable and it must be the
same for all backends. It is neat that journal supports additional
fields, but an average user still posts the output of plain
journalctl, without "--output verbose" (which would also be hard
to read).
Also, we get used to a certain logging format, so having different
formats is confusing. If one format is better then another, it should
be used for all backends: syslog, journal and debug.
The only question is, what is the best format.
- the timestamp: I find it useful to see how much time between two
events passed. The timestamp printed by syslog doesn't have sufficient
granularity, and the internal journal fields are not readily available.
We used to print the timestamps for <error>, <debug> and <trace>,
but ommited them for <info> and <warn> levels. We now print them for
all levels, which has a uniform alignment.
- the location: the "[file:line] func():" part is mostly redundant
and results in wide lines. It also causes a misalignment of the
logging lines, or -- as I recently added alignment of the location --
it results in awkward whitespace and truncation.
But the location is really just necessary because our logging messages
are bad:
"<debug> [1456397604.038226] (9) 11-dhclient succeeded"
The solution to this is not
"<debug> [1456397604.038226] [nm-dispatcher.c:358] dispatcher_results_process(): (9) 11-dhclient succeeded"
but a properly worded message:
"<debug> [1456397604.038226] dispatcher: request #9, script 11-dhclient succeeded"
- logging-message: we need to write better logging messages.
I like some form of "tags" that are easy to grep:
"platform: signal: link changed: 4: ..."
Downside is, that this is not nice to read as a full sentence.
So, especially for <info> and <warn> logging, more human readable
messages are better.
We should find a compromise, where the log message explains what
happens, but is still concise and contains patterns that are easy
to grep and identify visually.
https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00077.html
2016-02-25 17:21:29 +01:00
|
|
|
log_format_flags = _LOG_FORMAT_FLAG_DEFAULT;
|
|
|
|
|
|
2015-07-08 21:44:01 +02:00
|
|
|
if (strcmp (logging_backend, "debug") == 0) {
|
2015-10-07 11:07:09 +02:00
|
|
|
global.log_backend = LOG_BACKEND_SYSLOG;
|
2010-05-04 15:03:59 -07:00
|
|
|
openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER);
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
2015-07-08 21:44:01 +02:00
|
|
|
} else if (strcmp (logging_backend, "syslog") != 0) {
|
2016-02-13 16:27:11 +01:00
|
|
|
global.log_backend = LOG_BACKEND_JOURNAL;
|
2016-05-23 12:02:31 +02:00
|
|
|
global.uses_syslog = TRUE;
|
2015-07-08 16:21:21 +02:00
|
|
|
|
|
|
|
|
/* ensure we read a monotonic timestamp. Reading the timestamp the first
|
|
|
|
|
* time causes a logging message. We don't want to do that during _nm_log_impl. */
|
|
|
|
|
nm_utils_get_monotonic_timestamp_ns ();
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
2015-10-07 11:07:09 +02:00
|
|
|
global.log_backend = LOG_BACKEND_SYSLOG;
|
2016-05-23 12:02:31 +02:00
|
|
|
global.uses_syslog = TRUE;
|
2013-05-17 15:18:03 -04:00
|
|
|
openlog (G_LOG_DOMAIN, LOG_PID, LOG_DAEMON);
|
2015-07-08 16:21:21 +02:00
|
|
|
}
|
2013-06-14 14:51:04 -04:00
|
|
|
|
2016-02-13 16:27:11 +01:00
|
|
|
global.log_format_flags = log_format_flags;
|
|
|
|
|
|
2015-07-08 17:01:15 +02:00
|
|
|
g_log_set_handler (G_LOG_DOMAIN,
|
|
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
|
|
|
|
nm_log_handler,
|
|
|
|
|
NULL);
|
2006-02-27 04:31:52 +00:00
|
|
|
}
|
|
|
|
|
|