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 <thaller@redhat.com>
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user