From 573576bedd4788ce6cb54410dceb016bc332d97c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 12 Feb 2014 11:44:12 +0100 Subject: [PATCH] core/logging: define nm_log() to check for nm_logging_enabled() first Change the definition of nm_log() to first check whether logging is enabled. This has the benefit, that the logging arguments don't have to be evaluated if logging is disabled. With this change, you must ensure, that calling any logging function is side-effect-free. For example: nm_log_debug ("This is a bug %s, %d", has_side_effect (), ++i); would be a bug, because the logging arguments get only evaluated depending on the logging setup. Signed-off-by: Thomas Haller --- src/nm-logging.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nm-logging.h b/src/nm-logging.h index ea94d78d1..a4392860c 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -97,8 +97,14 @@ GQuark nm_logging_error_quark (void); #define nm_log_info(domain, ...) nm_log (LOGL_INFO, (domain), __VA_ARGS__) #define nm_log_dbg(domain, ...) nm_log (LOGL_DEBUG, (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, ...) \ - _nm_log (G_STRLOC, G_STRFUNC, (level), (domain), __VA_ARGS__) + G_STMT_START { \ + if (nm_logging_enabled ((level), (domain))) { \ + _nm_log (G_STRLOC, G_STRFUNC, (level), (domain), __VA_ARGS__); \ + } \ + } G_STMT_END void _nm_log (const char *loc, const char *func,