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>
This commit is contained in:
Thomas Haller 2014-02-12 21:54:26 +01:00
parent 573576bedd
commit ca7329f7d4

View file

@ -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,