diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-10-21 14:25:23 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-11-10 17:51:03 +0100 |
commit | 0f06e64c3de06d535bd36365993eab8170a09dcb (patch) | |
tree | f7492e4a36a2563f91a961a2ac8fd954a1aec8ca /src/basic | |
parent | log: Add log_ratelimit_full() (diff) | |
download | systemd-0f06e64c3de06d535bd36365993eab8170a09dcb.tar.xz systemd-0f06e64c3de06d535bd36365993eab8170a09dcb.zip |
log: Add ratelimit argument to ratelimit log macros
Allows configuring the ratelimit per logging statement.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/log.h | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/basic/log.h b/src/basic/log.h index 8a828c1d2d..8912be233d 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -375,15 +375,12 @@ typedef struct LogRateLimit { RateLimit ratelimit; } LogRateLimit; -#define log_ratelimit_internal(_level, _error, _format, _file, _line, _func, ...) \ +#define log_ratelimit_internal(_level, _error, _ratelimit, _format, _file, _line, _func, ...) \ ({ \ int _log_ratelimit_error = (_error); \ int _log_ratelimit_level = (_level); \ static LogRateLimit _log_ratelimit = { \ - .ratelimit = { \ - .interval = 1 * USEC_PER_SEC, \ - .burst = 1, \ - }, \ + .ratelimit = (_ratelimit), \ }; \ unsigned _num_dropped_errors = ratelimit_num_dropped(&_log_ratelimit.ratelimit); \ if (_log_ratelimit_error != _log_ratelimit.error || _log_ratelimit_level != _log_ratelimit.level) { \ @@ -398,14 +395,14 @@ typedef struct LogRateLimit { _log_ratelimit_error; \ }) -#define log_ratelimit_full_errno(level, error, format, ...) \ +#define log_ratelimit_full_errno(level, error, _ratelimit, format, ...) \ ({ \ int _level = (level), _e = (error); \ _e = (log_get_max_level() >= LOG_PRI(_level)) \ - ? log_ratelimit_internal(_level, _e, format, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__) \ + ? log_ratelimit_internal(_level, _e, _ratelimit, format, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__) \ : -ERRNO_VALUE(_e); \ _e < 0 ? _e : -ESTRPIPE; \ }) -#define log_ratelimit_full(level, format, ...) \ - log_ratelimit_full_errno(level, 0, format, ##__VA_ARGS__) +#define log_ratelimit_full(level, _ratelimit, format, ...) \ + log_ratelimit_full_errno(level, 0, _ratelimit, format, ##__VA_ARGS__) |