On Fri, 2013-05-17 at 15:05 -0400, Pavel Simerda wrote:

> Any more resources/documentation/posts for that? 

Look at the attached patch as a demo.  Results:

bash-4.2# journalctl NM_IFACE=eth0
-- Logs begin at Mon 2013-03-25 18:35:24 EDT, end at Fri 2013-05-17 16:31:52 
EDT. --
May 17 16:31:18 qemux86-64 NetworkManager[327]: Bound interface eth0
bash-4.2# 

> As a side note, in future, I'll be adding a dependency on Jiří Pírko's libndp

Link?

>From f5554e5371b27c564b0e248d6ccefd9da4176916 Mon Sep 17 00:00:00 2001
From: Colin Walters <[email protected]>
Date: Fri, 17 May 2013 16:35:14 -0400
Subject: [PATCH] Demo structured logging

---
 configure.ac                      |   11 +++++++++++
 src/Makefile.am                   |    3 +++
 src/dhcp-manager/nm-dhcp-client.c |   10 ++++++++++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index 43e420f..d7641fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -291,6 +291,17 @@ if test "$with_session_tracking" = "consolekit"; then
 fi
 AC_MSG_RESULT($with_session_tracking)
 
+AC_ARG_WITH(systemd-journal,
+	    AS_HELP_STRING([--without-systemd-journal], [Use systemd @<:@default=auto@:>@]),
+	    [], [with_systemd_journal=auto])
+AS_IF([test x$with_systemd_journal != xno], [
+  PKG_CHECK_MODULES([SYSTEMD_JOURNAL], [libsystemd-journal >= 200], have_systemd_journal=yes, have_systemd_journal=no)
+  ])
+AM_CONDITIONAL(ENABLE_SYSTEMD_JOURNAL, test x$have_systemd_journal = xyes)
+AS_IF([test x$have_systemd_journal = xyes], [
+  AC_DEFINE([ENABLE_SYSTEMD_JOURNAL],[1],[Define if you want to build with systemd journal support])
+])
+
 AC_ARG_WITH(suspend-resume, AS_HELP_STRING([--with-suspend-resume=upower|systemd], [Build NetworkManager with specific suspend/resume support]))
 if test "z$with_suspend_resume" = "z"; then
     PKG_CHECK_EXISTS([libsystemd-login >= 183], [have_systemd_inhibit=yes], [have_systemd_inhibit=no])
diff --git a/src/Makefile.am b/src/Makefile.am
index d34e911..b7b49ef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -345,6 +345,7 @@ AM_CPPFLAGS = \
 	$(MM_GLIB_CFLAGS) \
 	$(POLKIT_CFLAGS) \
 	$(SYSTEMD_LOGIN_CFLAGS) \
+	$(SYSTEMD_JOURNAL_CFLAGS) \
 	\
 	-DBINDIR=\"$(bindir)\" \
 	-DDATADIR=\"$(datadir)\" \
@@ -375,6 +376,7 @@ libNetworkManager_la_SOURCES = \
 
 libNetworkManager_la_LIBADD = \
 	$(top_builddir)/libnm-util/libnm-util.la \
+	$(top_builddir)/libgsystem.la \
 	$(BLUEZ_LIBS) \
 	$(DBUS_LIBS) \
 	$(GLIB_LIBS) \
@@ -383,6 +385,7 @@ libNetworkManager_la_LIBADD = \
 	$(MM_GLIB_LIBS) \
 	$(POLKIT_LIBS) \
 	$(SYSTEMD_LOGIN_LIBS) \
+	$(SYSTEMD_JOURNAL_LIBS) \
 	$(LIBDL) \
 	$(LIBM)
 
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index e6c36e9..17d70e7 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -32,6 +32,7 @@
 #include "nm-logging.h"
 #include "nm-dbus-glib-types.h"
 #include "nm-dhcp-client.h"
+#include "libgsystem.h"
 
 typedef struct {
 	char *       iface;
@@ -728,6 +729,15 @@ nm_dhcp_client_new_options (NMDHCPClient *self,
 	if (state_is_bound (new_state)) {
 		/* Cancel the timeout if the DHCP client is now bound */
 		timeout_cleanup (self);
+		{
+			#define BOUND_IFACE_MSGID "bc498d9d08dfdda9432d74a6737ac73e"
+			gs_free char *iface_key = g_strconcat ("NM_IFACE=", priv->iface);
+			gs_free char *msg = g_strdup_printf ("Bound interface %s", priv->iface);
+			char *keys[] = { "MESSAGE_ID=" BOUND_IFACE_MSGID,
+							 iface_key,
+							 NULL };
+			gs_log_structured (msg, keys);
+		}
 	}
 
 	if (priv->ipv6) {
-- 
1.7.1

_______________________________________________
networkmanager-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to