summary refs log tree commit diff
path: root/src/nm-logging.h
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-01-22 00:29:39 +0100
committerMichael Biebl <biebl@debian.org>2015-01-22 00:29:39 +0100
commit2c032d8f1c6292c1338a615e6ec40252889ba85c (patch)
tree1f77182220b2b0264288ba4a476ab47e5bc48716 /src/nm-logging.h
parent33491bc4279481db8ae47213e34a6d695a0e8830 (diff)
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'src/nm-logging.h')
-rw-r--r--src/nm-logging.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/nm-logging.h b/src/nm-logging.h
new file mode 100644
index 00000000..4ab2db3a
--- /dev/null
+++ b/src/nm-logging.h
@@ -0,0 +1,159 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* 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.
+ *
+ * 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.
+ *
+ * Copyright (C) 2006 - 2012 Red Hat, Inc.
+ * Copyright (C) 2006 - 2008 Novell, Inc.
+ */
+
+#ifndef __NETWORKMANAGER_LOGGING_H__
+#define __NETWORKMANAGER_LOGGING_H__
+
+#ifdef __NM_TEST_UTILS_H__
+#error nm-test-utils.h must be included as last header
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "nm-utils-internal.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), /* WiFi 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_WIMAX      = (1LL << 23),
+	LOGD_INFINIBAND = (1LL << 24),
+	LOGD_FIREWALL   = (1LL << 25),
+	LOGD_ADSL       = (1LL << 26),
+	LOGD_BOND       = (1LL << 27),
+	LOGD_VLAN       = (1LL << 28),
+	LOGD_BRIDGE     = (1LL << 29),
+	LOGD_DBUS_PROPS = (1LL << 30),
+	LOGD_TEAM       = (1LL << 31),
+	LOGD_CONCHECK   = (1LL << 32),
+	LOGD_DCB        = (1LL << 33), /* Data Center Bridging */
+	LOGD_DISPATCH   = (1LL << 34),
+
+	__LOGD_MAX,
+	LOGD_ALL       = ((__LOGD_MAX - 1LL) << 1) - 1LL,
+	LOGD_DEFAULT   = LOGD_ALL & ~(
+	                              LOGD_DBUS_PROPS |
+	                              LOGD_WIFI_SCAN |
+	                              0),
+
+	/* aliases: */
+	LOGD_DHCP       = LOGD_DHCP4 | LOGD_DHCP6,
+	LOGD_IP         = LOGD_IP4 | LOGD_IP6,
+	LOGD_HW         = LOGD_PLATFORM,
+} NMLogDomain;
+
+/* Log levels */
+typedef enum  { /*< skip >*/
+	LOGL_TRACE,
+	LOGL_DEBUG,
+	LOGL_INFO,
+	LOGL_WARN,
+	LOGL_ERR,
+
+	LOGL_MAX
+} NMLogLevel;
+
+#define nm_log_err(domain, ...)     nm_log (LOGL_ERR,   (domain), __VA_ARGS__)
+#define nm_log_warn(domain, ...)    nm_log (LOGL_WARN,  (domain), __VA_ARGS__)
+#define nm_log_info(domain, ...)    nm_log (LOGL_INFO,  (domain), __VA_ARGS__)
+#define nm_log_dbg(domain, ...)     nm_log (LOGL_DEBUG, (domain), __VA_ARGS__)
+#define nm_log_trace(domain, ...)   nm_log (LOGL_TRACE, (domain), __VA_ARGS__)
+
+/* nm_log() only evaluates it's argument list after checking
+ * whether logging for the given level/domain is enabled.  */
+#define nm_log(level, domain, ...) \
+    G_STMT_START { \
+        if (nm_logging_enabled ((level), (domain))) { \
+            _nm_log (__FILE__, __LINE__, G_STRFUNC, (level), (domain), __VA_ARGS__); \
+        } \
+    } G_STMT_END
+
+
+#define _nm_log_ptr(level, domain, self, ...) \
+   nm_log ((level), (domain), "[%p] " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), self _NM_UTILS_MACRO_REST(__VA_ARGS__))
+
+/* log a message for an object (with providing a generic @self pointer) */
+#define nm_log_ptr(level, domain, self, ...) \
+    G_STMT_START { \
+        if ((level) <= LOGL_DEBUG) { \
+            _nm_log_ptr ((level), (domain), (self), __VA_ARGS__); \
+        } else { \
+            nm_log ((level), (domain), __VA_ARGS__); \
+        } \
+    } G_STMT_END
+
+
+#define _nm_log_obj(level, domain, self, ...) \
+    _nm_log_ptr ((level), (domain), (self), __VA_ARGS__)
+
+/* log a message for an object (with providing a @self pointer to a GObject).
+ * Contrary to nm_log_ptr(), @self must be a GObject type (or %NULL).
+ * As of now, nm_log_obj() is identical to nm_log_ptr(), but we might change that */
+#define nm_log_obj(level, domain, self, ...) \
+    nm_log_ptr ((level), (domain), (self), __VA_ARGS__)
+
+
+void _nm_log (const char *file,
+              guint line,
+              const char *func,
+              NMLogLevel level,
+              NMLogDomain domain,
+              const char *fmt,
+              ...) __attribute__((__format__ (__printf__, 6, 7)));
+
+const char *nm_logging_level_to_string (void);
+const char *nm_logging_domains_to_string (void);
+gboolean nm_logging_enabled (NMLogLevel level, NMLogDomain domain);
+
+const char *nm_logging_all_levels_to_string (void);
+const char *nm_logging_all_domains_to_string (void);
+
+gboolean nm_logging_setup (const char  *level,
+                           const char  *domains,
+                           char       **bad_domains,
+                           GError     **error);
+void     nm_logging_syslog_openlog   (gboolean debug);
+void     nm_logging_syslog_closelog  (void);
+
+#endif /* __NETWORKMANAGER_LOGGING_H__ */