diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-01-13 15:45:06 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-03-25 16:35:33 -0400 |
commit | a62ac1719887f0756ceb516ce3b12cd2aee18191 (patch) | |
tree | b7a895aa35161abe919aa1cb9de08902b8d36e61 /src/lib/log/log.h | |
parent | 253fea84cf9504a733db6979e2fc140a8c702615 (diff) | |
download | tor-a62ac1719887f0756ceb516ce3b12cd2aee18191.tar.gz tor-a62ac1719887f0756ceb516ce3b12cd2aee18191.zip |
Add a new inline function to check whether debug logging is on
We already do this in our log_debug() macro, but there are times
when we'd like to avoid allocating or precomputing something that we
are only going to log if debugging is on.
Diffstat (limited to 'src/lib/log/log.h')
-rw-r--r-- | src/lib/log/log.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/log/log.h b/src/lib/log/log.h index 45e01f3391..fda984e78f 100644 --- a/src/lib/log/log.h +++ b/src/lib/log/log.h @@ -193,6 +193,15 @@ void tor_log_get_logfile_names(struct smartlist_t *out); extern int log_global_min_severity_; +static inline bool debug_logging_enabled(void); +/** + * Return true iff debug logging is enabled for at least one domain. + */ +static inline bool debug_logging_enabled(void) +{ + return PREDICT_UNLIKELY(log_global_min_severity_ == LOG_DEBUG); +} + void log_fn_(int severity, log_domain_mask_t domain, const char *funcname, const char *format, ...) CHECK_PRINTF(4,5); @@ -222,8 +231,8 @@ void tor_log_string(int severity, log_domain_mask_t domain, log_fn_ratelim_(ratelim, severity, domain, __FUNCTION__, args) #define log_debug(domain, args...) \ STMT_BEGIN \ - if (PREDICT_UNLIKELY(log_global_min_severity_ == LOG_DEBUG)) \ - log_fn_(LOG_DEBUG, domain, __FUNCTION__, args); \ + if (debug_logging_enabled()) \ + log_fn_(LOG_DEBUG, domain, __FUNCTION__, args); \ STMT_END #define log_info(domain, args...) \ log_fn_(LOG_INFO, domain, __FUNCTION__, args) @@ -240,8 +249,8 @@ void tor_log_string(int severity, log_domain_mask_t domain, #define log_debug(domain, args, ...) \ STMT_BEGIN \ - if (PREDICT_UNLIKELY(log_global_min_severity_ == LOG_DEBUG)) \ - log_fn_(LOG_DEBUG, domain, __FUNCTION__, args, ##__VA_ARGS__); \ + if (debug_logging_enabled()) \ + log_fn_(LOG_DEBUG, domain, __FUNCTION__, args, ##__VA_ARGS__); \ STMT_END #define log_info(domain, args,...) \ log_fn_(LOG_INFO, domain, __FUNCTION__, args, ##__VA_ARGS__) |