shared,core: move logging enums to header "shared/nm-utils/nm-logging-fwd.h"

In core ("src/"), we use "nm-logging.h" for all logging. This dispatches
for logging to syslog, glog or systemd-journald.

If we want to log from a shared component under "shared/", we need to
use a common logging function. Add "nm-utils/nm-logging-fwd.h" for
forward declaring the used logging mechaism.

The shared library will still need to link with "src/nm-logging.c"
or an alternative implementation, depending on whether it is used
inside core or not.
This commit is contained in:
Thomas Haller 2018-12-28 15:31:23 +01:00
parent 600f8ee5cc
commit ef53b47e7c
4 changed files with 121 additions and 82 deletions

View file

@ -309,6 +309,7 @@ shared_nm_utils_libnm_utils_base_la_SOURCES = \
shared/nm-utils/nm-hash-utils.h \
shared/nm-utils/nm-io-utils.c \
shared/nm-utils/nm-io-utils.h \
shared/nm-utils/nm-logging-fwd.h \
shared/nm-utils/nm-macros-internal.h \
shared/nm-utils/nm-obj.h \
shared/nm-utils/nm-random-utils.c \

View file

@ -0,0 +1,111 @@
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2006 - 2018 Red Hat, Inc.
* Copyright (C) 2006 - 2008 Novell, Inc.
*/
#ifndef __NM_LOGGING_DEFINES_H__
#define __NM_LOGGING_DEFINES_H__
/* Log domains */
typedef enum { /*< skip >*/
LOGD_NONE = 0LL,
LOGD_PLATFORM = (1LL << 0), /* Platform services */
LOGD_RFKILL = (1LL << 1),
LOGD_ETHER = (1LL << 2),
LOGD_WIFI = (1LL << 3),
LOGD_BT = (1LL << 4),
LOGD_MB = (1LL << 5), /* mobile broadband */
LOGD_DHCP4 = (1LL << 6),
LOGD_DHCP6 = (1LL << 7),
LOGD_PPP = (1LL << 8),
LOGD_WIFI_SCAN = (1LL << 9),
LOGD_IP4 = (1LL << 10),
LOGD_IP6 = (1LL << 11),
LOGD_AUTOIP4 = (1LL << 12),
LOGD_DNS = (1LL << 13),
LOGD_VPN = (1LL << 14),
LOGD_SHARING = (1LL << 15), /* Connection sharing/dnsmasq */
LOGD_SUPPLICANT = (1LL << 16), /* Wi-Fi and 802.1x */
LOGD_AGENTS = (1LL << 17), /* Secret agents */
LOGD_SETTINGS = (1LL << 18), /* Settings */
LOGD_SUSPEND = (1LL << 19), /* Suspend/Resume */
LOGD_CORE = (1LL << 20), /* Core daemon and policy stuff */
LOGD_DEVICE = (1LL << 21), /* Device state and activation */
LOGD_OLPC = (1LL << 22),
LOGD_INFINIBAND = (1LL << 23),
LOGD_FIREWALL = (1LL << 24),
LOGD_ADSL = (1LL << 25),
LOGD_BOND = (1LL << 26),
LOGD_VLAN = (1LL << 27),
LOGD_BRIDGE = (1LL << 28),
LOGD_DBUS_PROPS = (1LL << 29),
LOGD_TEAM = (1LL << 30),
LOGD_CONCHECK = (1LL << 31),
LOGD_DCB = (1LL << 32), /* Data Center Bridging */
LOGD_DISPATCH = (1LL << 33),
LOGD_AUDIT = (1LL << 34),
LOGD_SYSTEMD = (1LL << 35),
LOGD_VPN_PLUGIN = (1LL << 36),
LOGD_PROXY = (1LL << 37),
__LOGD_MAX,
LOGD_ALL = (((__LOGD_MAX - 1LL) << 1) - 1LL),
LOGD_DEFAULT = LOGD_ALL & ~(
LOGD_DBUS_PROPS |
LOGD_WIFI_SCAN |
LOGD_VPN_PLUGIN |
0),
/* aliases: */
LOGD_DHCP = LOGD_DHCP4 | LOGD_DHCP6,
LOGD_IP = LOGD_IP4 | LOGD_IP6,
} NMLogDomain;
/* Log levels */
typedef enum { /*< skip >*/
LOGL_TRACE,
LOGL_DEBUG,
LOGL_INFO,
LOGL_WARN,
LOGL_ERR,
_LOGL_N_REAL, /* the number of actual logging levels */
_LOGL_OFF = _LOGL_N_REAL, /* special logging level that is always disabled. */
_LOGL_KEEP, /* special logging level to indicate that the logging level should not be changed. */
_LOGL_N, /* the number of logging levels including "OFF" */
} NMLogLevel;
gboolean _nm_log_enabled (NMLogLevel level,
NMLogDomain domain);
void _nm_log_impl (const char *file,
guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
int error,
const char *ifname,
const char *con_uuid,
const char *fmt,
...) _nm_printf (9, 10);
#endif /* __NM_LOGGING_DEFINES_H__ */

View file

@ -550,6 +550,13 @@ nm_logging_get_level (NMLogDomain domain)
return sl;
}
gboolean
_nm_log_enabled (NMLogLevel level,
NMLogDomain domain)
{
return nm_logging_enabled (level, domain);
}
#if SYSTEMD_JOURNAL
static void
_iovec_set (struct iovec *iov, const void *str, gsize len)

View file

@ -26,65 +26,12 @@
#error nm-test-utils.h must be included as last header
#endif
#include "nm-utils/nm-logging-fwd.h"
#define NM_LOG_CONFIG_BACKEND_DEBUG "debug"
#define NM_LOG_CONFIG_BACKEND_SYSLOG "syslog"
#define NM_LOG_CONFIG_BACKEND_JOURNAL "journal"
/* Log domains */
typedef enum { /*< skip >*/
LOGD_NONE = 0LL,
LOGD_PLATFORM = (1LL << 0), /* Platform services */
LOGD_RFKILL = (1LL << 1),
LOGD_ETHER = (1LL << 2),
LOGD_WIFI = (1LL << 3),
LOGD_BT = (1LL << 4),
LOGD_MB = (1LL << 5), /* mobile broadband */
LOGD_DHCP4 = (1LL << 6),
LOGD_DHCP6 = (1LL << 7),
LOGD_PPP = (1LL << 8),
LOGD_WIFI_SCAN = (1LL << 9),
LOGD_IP4 = (1LL << 10),
LOGD_IP6 = (1LL << 11),
LOGD_AUTOIP4 = (1LL << 12),
LOGD_DNS = (1LL << 13),
LOGD_VPN = (1LL << 14),
LOGD_SHARING = (1LL << 15), /* Connection sharing/dnsmasq */
LOGD_SUPPLICANT = (1LL << 16), /* Wi-Fi and 802.1x */
LOGD_AGENTS = (1LL << 17), /* Secret agents */
LOGD_SETTINGS = (1LL << 18), /* Settings */
LOGD_SUSPEND = (1LL << 19), /* Suspend/Resume */
LOGD_CORE = (1LL << 20), /* Core daemon and policy stuff */
LOGD_DEVICE = (1LL << 21), /* Device state and activation */
LOGD_OLPC = (1LL << 22),
LOGD_INFINIBAND = (1LL << 23),
LOGD_FIREWALL = (1LL << 24),
LOGD_ADSL = (1LL << 25),
LOGD_BOND = (1LL << 26),
LOGD_VLAN = (1LL << 27),
LOGD_BRIDGE = (1LL << 28),
LOGD_DBUS_PROPS = (1LL << 29),
LOGD_TEAM = (1LL << 30),
LOGD_CONCHECK = (1LL << 31),
LOGD_DCB = (1LL << 32), /* Data Center Bridging */
LOGD_DISPATCH = (1LL << 33),
LOGD_AUDIT = (1LL << 34),
LOGD_SYSTEMD = (1LL << 35),
LOGD_VPN_PLUGIN = (1LL << 36),
LOGD_PROXY = (1LL << 37),
__LOGD_MAX,
LOGD_ALL = (((__LOGD_MAX - 1LL) << 1) - 1LL),
LOGD_DEFAULT = LOGD_ALL & ~(
LOGD_DBUS_PROPS |
LOGD_WIFI_SCAN |
LOGD_VPN_PLUGIN |
0),
/* aliases: */
LOGD_DHCP = LOGD_DHCP4 | LOGD_DHCP6,
LOGD_IP = LOGD_IP4 | LOGD_IP6,
} NMLogDomain;
static inline NMLogDomain
LOGD_IP_from_af (int addr_family)
{
@ -95,22 +42,6 @@ LOGD_IP_from_af (int addr_family)
g_return_val_if_reached (LOGD_NONE);
}
/* Log levels */
typedef enum { /*< skip >*/
LOGL_TRACE,
LOGL_DEBUG,
LOGL_INFO,
LOGL_WARN,
LOGL_ERR,
_LOGL_N_REAL, /* the number of actual logging levels */
_LOGL_OFF = _LOGL_N_REAL, /* special logging level that is always disabled. */
_LOGL_KEEP, /* special logging level to indicate that the logging level should not be changed. */
_LOGL_N, /* the number of logging levels including "OFF" */
} NMLogLevel;
#define nm_log_err(domain, ...) nm_log (LOGL_ERR, (domain), NULL, NULL, __VA_ARGS__)
#define nm_log_warn(domain, ...) nm_log (LOGL_WARN, (domain), NULL, NULL, __VA_ARGS__)
#define nm_log_info(domain, ...) nm_log (LOGL_INFO, (domain), NULL, NULL, __VA_ARGS__)
@ -204,17 +135,6 @@ _nm_log_ptr_is_debug (NMLogLevel level)
prefix, \
__VA_ARGS__)
void _nm_log_impl (const char *file,
guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
int error,
const char *ifname,
const char *con_uuid,
const char *fmt,
...) _nm_printf (9, 10);
const char *nm_logging_level_to_string (void);
const char *nm_logging_domains_to_string (void);