diff options
-rw-r--r-- | src/pulsecore/log.c | 8 | ||||
-rw-r--r-- | src/pulsecore/log.h | 2 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c index adf2f112..9a7f7cac 100644 --- a/src/pulsecore/log.c +++ b/src/pulsecore/log.c @@ -47,6 +47,7 @@ #include <pulsecore/core-util.h> #include <pulsecore/rtclock.h> #include <pulsecore/once.h> +#include <pulsecore/ratelimit.h> #include "log.h" @@ -375,3 +376,10 @@ void pa_log_level(pa_log_level_t level, const char *format, ...) { pa_log_levelv_meta(level, NULL, 0, NULL, format, ap); va_end(ap); } + +pa_bool_t pa_log_ratelimit(void) { + /* Not more than 10 messages every 5s */ + static PA_DEFINE_RATELIMIT(ratelimit, 5 * PA_USEC_PER_SEC, 10); + + return pa_ratelimit_test(&ratelimit); +} diff --git a/src/pulsecore/log.h b/src/pulsecore/log.h index 3d66e903..77adb791 100644 --- a/src/pulsecore/log.h +++ b/src/pulsecore/log.h @@ -109,4 +109,6 @@ LOG_FUNC(error, PA_LOG_ERROR) #define pa_log pa_log_error +pa_bool_t pa_log_ratelimit(void); + #endif |