summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-10-20 21:17:55 +0200
committerKay Sievers <kay@vrfy.org>2013-10-20 21:26:47 +0200
commit87ff6b1c2a607c47b2374c5be41ac01302714979 (patch)
treec9f0547388990d90a877ec0b85d2696e15320108 /src
parent145d22584ff3a64cfd4798ad4fde5ed6e2428183 (diff)
log: avoid calling the logging functions for log levels above the current maximum
Messages with log levels above the current maximum log level will be dropped inside log_meta(). But to be able to call the function, all parameters for the function need to be provided. This can easily get expensive, if values need to be calculated or functions are used in parameters. Avoid all useless work by checking inside the macro, before we look at any parameters passed to the logging functions.
Diffstat (limited to 'src')
-rw-r--r--src/shared/log.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/shared/log.h b/src/shared/log.h
index 9ce99ef9fa..ac20a985c5 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -136,13 +136,17 @@ _noreturn_ void log_assert_failed_unreachable(
int line,
const char *func);
-#define log_full(level, ...) log_meta(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
-
-#define log_debug(...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
-#define log_info(...) log_meta(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
-#define log_notice(...) log_meta(LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
-#define log_warning(...) log_meta(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
-#define log_error(...) log_meta(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__)
+#define log_full(level, ...) \
+do { \
+ if (log_get_max_level() >= (level)) \
+ log_meta(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__); \
+} while (0)
+
+#define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__)
+#define log_info(...) log_full(LOG_INFO, __VA_ARGS__)
+#define log_notice(...) log_full(LOG_NOTICE, __VA_ARGS__)
+#define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__)
+#define log_error(...) log_full(LOG_ERR, __VA_ARGS__)
#define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__)