diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-12-26 10:51:58 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-12-26 11:07:11 -0500 |
commit | f269e0f9a51ecc7f22e62bde302afd8574d2f96f (patch) | |
tree | bb5e6e17261a5142efc9a939674c0cf9027cdd90 /src/common/torlog.h | |
parent | 127cb39ffcacbcd99633671e92d299ef53bbac46 (diff) | |
download | tor-f269e0f9a51ecc7f22e62bde302afd8574d2f96f.tar.gz tor-f269e0f9a51ecc7f22e62bde302afd8574d2f96f.zip |
Wrapper function for the common rate-limited-log pattern.
Diffstat (limited to 'src/common/torlog.h')
-rw-r--r-- | src/common/torlog.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/torlog.h b/src/common/torlog.h index ab97f9c9a7..cc1fa64071 100644 --- a/src/common/torlog.h +++ b/src/common/torlog.h @@ -161,10 +161,20 @@ extern int log_global_min_severity_; void log_fn_(int severity, log_domain_mask_t domain, const char *funcname, const char *format, ...) CHECK_PRINTF(4,5); +struct ratelim_t; +void log_fn_ratelim_(struct ratelim_t *ratelim, int severity, + log_domain_mask_t domain, const char *funcname, + const char *format, ...) + CHECK_PRINTF(5,6); /** Log a message at level <b>severity</b>, using a pretty-printed version * of the current function name. */ #define log_fn(severity, domain, args...) \ log_fn_(severity, domain, __PRETTY_FUNCTION__, args) +/** As log_fn, but use <b>ratelim</b> (an instance of ratelim_t) to control + * the frequency at which messages can appear. + */ +#define log_fn_ratelim(ratelim, severity, domain, args...) \ + log_fn_ratelim_(ratelim, severity, domain, __PRETTY_FUNCTION__, args) #define log_debug(domain, args...) \ STMT_BEGIN \ if (PREDICT_UNLIKELY(log_global_min_severity_ == LOG_DEBUG)) \ @@ -182,6 +192,9 @@ void log_fn_(int severity, log_domain_mask_t domain, #else /* ! defined(__GNUC__) */ void log_fn_(int severity, log_domain_mask_t domain, const char *format, ...); +struct ratelim_t; +void log_fn_ratelim_(struct ratelim_t *ratelim, int severity, + log_domain_mask_t domain, const char *format, ...); void log_debug_(log_domain_mask_t domain, const char *format, ...); void log_info_(log_domain_mask_t domain, const char *format, ...); void log_notice_(log_domain_mask_t domain, const char *format, ...); @@ -191,6 +204,7 @@ void log_err_(log_domain_mask_t domain, const char *format, ...); #if defined(_MSC_VER) && _MSC_VER < 1300 /* MSVC 6 and earlier don't have __func__, or even __LINE__. */ #define log_fn log_fn_ +#define log_fn_ratelim log_fn_ratelim_ #define log_debug log_debug_ #define log_info log_info_ #define log_notice log_notice_ @@ -204,6 +218,7 @@ extern const char *log_fn_function_name_; * do {...} while (0) trick to wrap this macro, since the macro can't take * arguments. */ #define log_fn (log_fn_function_name_=__func__),log_fn_ +#define log_fn_ratelim (log_fn_function_name_=__func__),log_fn_ratelim_ #define log_debug (log_fn_function_name_=__func__),log_debug_ #define log_info (log_fn_function_name_=__func__),log_info_ #define log_notice (log_fn_function_name_=__func__),log_notice_ |