diff options
author | Thomas Haller <thaller@redhat.com> | 2014-02-12 11:44:12 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-10-30 11:45:54 +0100 |
commit | dbfb41bfd8ce2bde2095b00caaf326069d902e4c (patch) | |
tree | 9d20a1e4d54d84db9a81ceb18d82f8b2e0ec4b5e | |
parent | 3f859a21dceb01027bfa05952cdbe7cdf7757a97 (diff) | |
download | NetworkManager-dbfb41bfd8ce2bde2095b00caaf326069d902e4c.tar.gz |
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>
(cherry picked from commit 573576bedd4788ce6cb54410dceb016bc332d97c)
-rw-r--r-- | src/logging/nm-logging.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/logging/nm-logging.h b/src/logging/nm-logging.h index ea94d78d11..a4392860cc 100644 --- a/src/logging/nm-logging.h +++ b/src/logging/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, |