summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-02-12 21:54:26 +0100
committerThomas Haller <thaller@redhat.com>2014-10-30 11:45:54 +0100
commitb941b34f52edd322d45001b80147720dfab7d613 (patch)
tree6d544de563f995def17fd9eb883f16ad9a22d83a
parentdbfb41bfd8ce2bde2095b00caaf326069d902e4c (diff)
downloadNetworkManager-b941b34f52edd322d45001b80147720dfab7d613.tar.gz
core/logging: add new logging macro nm_log_obj()
Add new macro nm_log_obj() to prefix the log line with a pointer value as identifier. This macro can be used to give each logging line a common prefix with defined format. It is mainly intended to print a message "for" an object, for example inside a method function. Signed-off-by: Thomas Haller <thaller@redhat.com> (cherry picked from commit ca7329f7d47058a66ad66d0cec69b08bb08fea4b)
-rw-r--r--src/logging/nm-logging.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/logging/nm-logging.h b/src/logging/nm-logging.h
index a4392860cc..fdbed088d6 100644
--- a/src/logging/nm-logging.h
+++ b/src/logging/nm-logging.h
@@ -29,6 +29,8 @@
#include <glib.h>
#include <glib-object.h>
+#include "nm-utils-internal.h"
+
/* Log domains */
enum {
LOGD_NONE = 0LL,
@@ -106,6 +108,31 @@ GQuark nm_logging_error_quark (void);
} \
} 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 *loc,
const char *func,
guint32 level,