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
|
|
|
*/
|
|
|
|
|
|
2011-03-14 01:00:56 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
#define SD_JOURNAL_SUPPRESS_LOCATION
|
|
|
|
|
#include <systemd/sd-journal.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-04-06 16:42:31 -04:00
|
|
|
#include "nm-glib.h"
|
2006-02-27 04:31:52 +00:00
|
|
|
#include "nm-logging.h"
|
2014-10-16 16:47:30 -04:00
|
|
|
#include "nm-errors.h"
|
2015-07-08 16:21:21 +02:00
|
|
|
#include "gsystem-local-alloc.h"
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2013-06-14 14:51:04 -04:00
|
|
|
static void
|
|
|
|
|
nm_log_handler (const gchar *log_domain,
|
|
|
|
|
GLogLevelFlags level,
|
|
|
|
|
const gchar *message,
|
|
|
|
|
gpointer ignored);
|
|
|
|
|
|
2014-10-30 12:44:36 +01:00
|
|
|
static NMLogLevel log_level = LOGL_INFO;
|
2013-10-01 11:40:22 -04:00
|
|
|
static char *log_domains;
|
2014-10-30 12:44:36 +01:00
|
|
|
static NMLogDomain logging[LOGL_MAX];
|
2014-04-05 09:38:59 -04:00
|
|
|
static gboolean logging_set_up;
|
2015-07-08 17:13:59 +02:00
|
|
|
enum {
|
|
|
|
|
LOG_BACKEND_GLIB,
|
|
|
|
|
LOG_BACKEND_SYSLOG,
|
2015-07-08 16:21:21 +02:00
|
|
|
LOG_BACKEND_JOURNAL,
|
2015-07-08 21:37:35 +02:00
|
|
|
LOG_BACKEND_JOURNAL_SYSLOG_STYLE,
|
2015-07-08 17:13:59 +02:00
|
|
|
} log_backend = LOG_BACKEND_GLIB;
|
2014-02-12 11:30:29 +01:00
|
|
|
static char *logging_domains_to_string;
|
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;
|
|
|
|
|
int syslog_level;
|
|
|
|
|
GLogLevelFlags g_log_level;
|
|
|
|
|
gboolean full_details;
|
|
|
|
|
} LogLevelDesc;
|
|
|
|
|
|
|
|
|
|
static const LogLevelDesc level_desc[LOGL_MAX] = {
|
|
|
|
|
[LOGL_TRACE] = { "TRACE", "<trace>", LOG_DEBUG, G_LOG_LEVEL_DEBUG, TRUE },
|
|
|
|
|
[LOGL_DEBUG] = { "DEBUG", "<debug>", LOG_INFO, G_LOG_LEVEL_DEBUG, TRUE },
|
|
|
|
|
[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 },
|
2010-04-06 15:23:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const LogDesc domain_descs[] = {
|
2010-04-06 16:19:30 -07:00
|
|
|
{ LOGD_NONE, "NONE" },
|
2013-01-23 10:25:18 +01:00
|
|
|
{ LOGD_PLATFORM, "PLATFORM" },
|
2010-04-06 15:23:08 -07:00
|
|
|
{ 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" },
|
2010-12-10 12:36:02 -06:00
|
|
|
{ LOGD_AGENTS, "AGENTS" },
|
2010-12-10 12:32:22 -06:00
|
|
|
{ LOGD_SETTINGS, "SETTINGS" },
|
2010-04-06 15:23:08 -07:00
|
|
|
{ LOGD_SUSPEND, "SUSPEND" },
|
|
|
|
|
{ LOGD_CORE, "CORE" },
|
2010-04-06 16:25:42 -07:00
|
|
|
{ LOGD_DEVICE, "DEVICE" },
|
2014-05-12 18:51:52 +02:00
|
|
|
{ LOGD_OLPC, "OLPC" },
|
2011-10-14 10:13:49 -04:00
|
|
|
{ LOGD_INFINIBAND,"INFINIBAND" },
|
2011-12-06 16:51:17 -06:00
|
|
|
{ LOGD_FIREWALL, "FIREWALL" },
|
2011-05-26 13:04:59 -05:00
|
|
|
{ LOGD_ADSL, "ADSL" },
|
2012-10-31 17:31:38 +01:00
|
|
|
{ LOGD_BOND, "BOND" },
|
2012-10-31 17:36:18 +01:00
|
|
|
{ LOGD_VLAN, "VLAN" },
|
2013-01-22 12:04:37 -06:00
|
|
|
{ LOGD_BRIDGE, "BRIDGE" },
|
2013-08-06 16:29:09 -05:00
|
|
|
{ LOGD_DBUS_PROPS,"DBUS_PROPS" },
|
2013-07-25 15:36:45 +02:00
|
|
|
{ LOGD_TEAM, "TEAM" },
|
2013-07-31 10:14:25 -04:00
|
|
|
{ LOGD_CONCHECK, "CONCHECK" },
|
2013-10-03 21:38:59 -05:00
|
|
|
{ LOGD_DCB, "DCB" },
|
2014-03-31 14:26:28 -04:00
|
|
|
{ LOGD_DISPATCH, "DISPATCH" },
|
2015-07-13 10:19:33 +02:00
|
|
|
{ LOGD_AUDIT, "AUDIT" },
|
2010-04-06 15:23:08 -07:00
|
|
|
{ 0, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
/************************************************************************/
|
|
|
|
|
|
2014-07-18 11:11:23 +02:00
|
|
|
static void
|
2014-10-29 10:44:31 +01:00
|
|
|
_ensure_initialized (void)
|
2014-07-18 11:11:23 +02:00
|
|
|
{
|
|
|
|
|
if (G_UNLIKELY (!logging_set_up))
|
|
|
|
|
nm_logging_setup ("INFO", "DEFAULT", NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < LOGL_MAX; i++) {
|
2015-07-09 13:55:51 +02:00
|
|
|
if (!g_ascii_strcasecmp (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;
|
2014-10-30 12:44:36 +01:00
|
|
|
NMLogDomain new_logging[LOGL_MAX];
|
|
|
|
|
NMLogLevel new_log_level = 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;
|
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);
|
|
|
|
|
|
2014-04-05 09:38:59 -04:00
|
|
|
logging_set_up = TRUE;
|
|
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
for (i = 0; i < LOGL_MAX; i++)
|
|
|
|
|
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;
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* domains */
|
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 (!domains || !*domains)
|
|
|
|
|
domains = log_domains ? log_domains : "DEFAULT";
|
2012-10-31 17:19:38 +01: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;
|
|
|
|
|
|
|
|
|
|
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;
|
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 {
|
|
|
|
|
for (diter = &domain_descs[0]; diter->name; diter++) {
|
|
|
|
|
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
|
|
|
|
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 (!bits) {
|
|
|
|
|
if (!bad_domains) {
|
2014-10-16 16:47:30 -04:00
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN,
|
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
|
|
|
_("Unknown log domain '%s'"), *iter);
|
|
|
|
|
return FALSE;
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
2013-10-01 11:40:22 -04: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
|
|
|
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
|
|
|
|
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
|
|
|
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);
|
2013-10-01 11:40:22 -04: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
|
|
|
if (log_domains != (char *)domains) {
|
|
|
|
|
g_free (log_domains);
|
|
|
|
|
log_domains = g_strdup (domains);
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
g_clear_pointer (&logging_domains_to_string, g_free);
|
|
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
log_level = new_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
|
|
|
for (i = 0; i < LOGL_MAX; i++)
|
|
|
|
|
logging[i] = new_logging[i];
|
2013-10-01 11:40:22 -04: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-07-09 13:55:51 +02:00
|
|
|
return level_desc[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);
|
2013-10-01 11:40:22 -04:00
|
|
|
for (i = 0; i < LOGL_MAX; i++) {
|
2013-03-11 12:23:57 -04:00
|
|
|
if (str->len)
|
|
|
|
|
g_string_append_c (str, ',');
|
2015-07-09 13:55:51 +02:00
|
|
|
g_string_append (str, 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)
|
|
|
|
|
{
|
2014-07-18 11:11:23 +02:00
|
|
|
_ensure_initialized ();
|
|
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
if (G_UNLIKELY (!logging_domains_to_string)) {
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
GString *str;
|
|
|
|
|
int i;
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
/* We don't just return g_strdup (log_domains) because we want to expand
|
|
|
|
|
* "DEFAULT" and "ALL".
|
|
|
|
|
*/
|
2010-05-04 12:06:00 -07:00
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
str = g_string_sized_new (75);
|
|
|
|
|
for (diter = &domain_descs[0]; diter->name; diter++) {
|
|
|
|
|
/* If it's set for any lower level, it will also be set for LOGL_ERR */
|
|
|
|
|
if (!(diter->num & logging[LOGL_ERR]))
|
|
|
|
|
continue;
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
if (str->len)
|
|
|
|
|
g_string_append_c (str, ',');
|
|
|
|
|
g_string_append (str, diter->name);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
/* Check if it's logging at a lower level than the default. */
|
|
|
|
|
for (i = 0; i < log_level; i++) {
|
2013-10-01 11:40:22 -04:00
|
|
|
if (diter->num & logging[i]) {
|
2015-07-09 13:55:51 +02:00
|
|
|
g_string_append_printf (str, ":%s", level_desc[i].name);
|
2013-10-01 11:40:22 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-12 11:30:29 +01:00
|
|
|
/* Check if it's logging at a higher level than the default. */
|
|
|
|
|
if (!(diter->num & logging[log_level])) {
|
|
|
|
|
for (i = log_level + 1; i < LOGL_MAX; i++) {
|
|
|
|
|
if (diter->num & logging[i]) {
|
2015-07-09 13:55:51 +02:00
|
|
|
g_string_append_printf (str, ":%s", level_desc[i].name);
|
2014-02-12 11:30:29 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
2014-02-12 11:30:29 +01:00
|
|
|
logging_domains_to_string = g_string_free (str, FALSE);
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
2014-02-12 11:30:29 +01:00
|
|
|
return logging_domains_to_string;
|
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);
|
2013-03-11 12:23:57 -04:00
|
|
|
for (diter = &domain_descs[0]; diter->name; diter++) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-08 01:36:08 -05:00
|
|
|
gboolean
|
2014-10-30 12:44:36 +01:00
|
|
|
nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
|
2010-08-08 01:36:08 -05:00
|
|
|
{
|
2013-10-01 11:40:22 -04:00
|
|
|
g_return_val_if_fail (level < LOGL_MAX, FALSE);
|
|
|
|
|
|
2014-07-18 11:11:23 +02:00
|
|
|
_ensure_initialized ();
|
|
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
return !!(logging[level] & domain);
|
2011-05-19 13:31:52 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
__attribute__((__format__ (__printf__, 4, 5)))
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
#define _iovec_set_literal_string(iov, iov_free, i, str) _iovec_set_string ((iov), (iov_free), (i), (""str""), STRLEN (str))
|
|
|
|
|
#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;
|
2013-06-14 14:51:04 -04:00
|
|
|
char *fullmsg = NULL;
|
2010-04-06 15:23:08 -07:00
|
|
|
GTimeVal tv;
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
if ((guint) level >= LOGL_MAX)
|
|
|
|
|
g_return_if_reached ();
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2014-07-18 11:11:23 +02:00
|
|
|
_ensure_initialized ();
|
2014-04-05 09:38:59 -04:00
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
if (!(logging[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 */
|
|
|
|
|
if (error != 0)
|
|
|
|
|
errno = error;
|
|
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
va_start (args, fmt);
|
|
|
|
|
msg = g_strdup_vprintf (fmt, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2015-07-08 17:13:59 +02:00
|
|
|
switch (log_backend) {
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
case LOG_BACKEND_JOURNAL:
|
2015-07-08 21:37:35 +02:00
|
|
|
case LOG_BACKEND_JOURNAL_SYSLOG_STYLE:
|
2015-07-08 16:21:21 +02:00
|
|
|
{
|
|
|
|
|
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-07-09 13:55:51 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "PRIORITY=%d", level_desc[level].syslog_level);
|
2015-07-08 21:37:35 +02:00
|
|
|
if ( log_backend == LOG_BACKEND_JOURNAL_SYSLOG_STYLE
|
2015-07-09 13:55:51 +02:00
|
|
|
&& level_desc[level].full_details) {
|
2015-07-08 21:37:35 +02:00
|
|
|
g_get_current_time (&tv);
|
2015-07-09 13:55:51 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "MESSAGE=%-7s [%ld.%06ld] [%s:%u] %s(): %s", level_desc[level].level_str, tv.tv_sec, tv.tv_usec, file, line, func, msg);
|
2015-07-08 21:37:35 +02:00
|
|
|
} else
|
2015-07-09 13:55:51 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "MESSAGE=%-7s %s", level_desc[level].level_str, 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;
|
|
|
|
|
NMLogDomain dom = dom_all & logging[level];
|
|
|
|
|
|
|
|
|
|
for (diter = &domain_descs[0]; diter->name; diter++) {
|
|
|
|
|
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-07-09 13:55:51 +02:00
|
|
|
_iovec_set_format (iov, iov_free, i_field++, "NM_LOG_LEVEL=%s", level_desc[level].name);
|
2015-07-08 16:21:21 +02: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);
|
|
|
|
|
_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:
|
2015-07-09 13:55:51 +02:00
|
|
|
if (level_desc[level].full_details) {
|
2015-07-08 16:21:21 +02:00
|
|
|
g_get_current_time (&tv);
|
2015-07-09 13:55:51 +02:00
|
|
|
fullmsg = g_strdup_printf ("%-7s [%ld.%06ld] [%s:%u] %s(): %s", level_desc[level].level_str, tv.tv_sec, tv.tv_usec, file, line, func, msg);
|
2015-07-08 16:21:21 +02:00
|
|
|
} else
|
2015-07-09 13:55:51 +02:00
|
|
|
fullmsg = g_strdup_printf ("%-7s %s", level_desc[level].level_str, msg);
|
2015-07-08 16:21:21 +02:00
|
|
|
|
|
|
|
|
if (log_backend == LOG_BACKEND_SYSLOG)
|
2015-07-09 13:55:51 +02:00
|
|
|
syslog (level_desc[level].syslog_level, "%s", fullmsg);
|
2015-07-08 16:21:21 +02:00
|
|
|
else
|
2015-07-09 13:55:51 +02:00
|
|
|
g_log (G_LOG_DOMAIN, level_desc[level].g_log_level, "%s", 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);
|
2013-06-14 14:51:04 -04:00
|
|
|
g_free (fullmsg);
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
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-07-08 16:21:21 +02:00
|
|
|
switch (log_backend) {
|
|
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
case LOG_BACKEND_JOURNAL:
|
2015-07-08 21:37:35 +02:00
|
|
|
case LOG_BACKEND_JOURNAL_SYSLOG_STYLE:
|
2015-07-08 16:21:21 +02:00
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
"MESSAGE=%s", str_if_set (message, ""),
|
|
|
|
|
"SYSLOG_IDENTIFIER=%s", G_LOG_DOMAIN,
|
|
|
|
|
"SYSLOG_PID=%ld", (long) getpid (),
|
|
|
|
|
"SYSLOG_FACILITY=GLIB",
|
|
|
|
|
"GLIB_DOMAIN=%s", str_if_set (log_domain, ""),
|
|
|
|
|
"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:
|
|
|
|
|
syslog (syslog_priority, "%s", str_if_set (message, ""));
|
|
|
|
|
break;
|
|
|
|
|
}
|
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
|
|
|
{
|
2015-07-08 17:13:59 +02:00
|
|
|
if (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;
|
|
|
|
|
|
|
|
|
|
if (strcmp (logging_backend, "debug") == 0) {
|
2015-07-08 16:21:21 +02:00
|
|
|
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) {
|
|
|
|
|
if (strcmp (logging_backend, "journal-syslog-style") != 0)
|
2015-07-08 21:37:35 +02:00
|
|
|
log_backend = LOG_BACKEND_JOURNAL;
|
|
|
|
|
else
|
|
|
|
|
log_backend = LOG_BACKEND_JOURNAL_SYSLOG_STYLE;
|
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 {
|
|
|
|
|
log_backend = LOG_BACKEND_SYSLOG;
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|