va_end(args);
}
-void
-vlog_rate_limit(enum vlog_module module, enum vlog_level level,
- struct vlog_rate_limit *rl, const char *message, ...)
+bool
+vlog_should_drop(enum vlog_module module, enum vlog_level level,
+ struct vlog_rate_limit *rl)
{
- va_list args;
-
if (!vlog_is_enabled(module, level)) {
- return;
+ return true;
}
if (rl->tokens < VLOG_MSG_TOKENS) {
rl->first_dropped = now;
}
rl->n_dropped++;
- return;
+ return true;
}
}
rl->tokens -= VLOG_MSG_TOKENS;
- va_start(args, message);
- vlog_valist(module, level, message, args);
- va_end(args);
-
if (rl->n_dropped) {
vlog(module, level,
"Dropped %u messages in last %u seconds due to excessive rate",
rl->n_dropped, (unsigned int) (time_now() - rl->first_dropped));
rl->n_dropped = 0;
}
+ return false;
+}
+
+void
+vlog_rate_limit(enum vlog_module module, enum vlog_level level,
+ struct vlog_rate_limit *rl, const char *message, ...)
+{
+ if (!vlog_should_drop(module, level, rl)) {
+ va_list args;
+
+ va_start(args, message);
+ vlog_valist(module, level, message, args);
+ va_end(args);
+ }
}
void
char *vlog_set_levels_from_string(const char *);
char *vlog_get_levels(void);
bool vlog_is_enabled(enum vlog_module, enum vlog_level);
+bool vlog_should_drop(enum vlog_module, enum vlog_level,
+ struct vlog_rate_limit *);
void vlog_set_verbosity(const char *arg);
/* Configuring log facilities. */
#define VLOG_IS_INFO_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_INFO)
#define VLOG_IS_DBG_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_DBG)
-/* Convenience macros. To use these, define THIS_MODULE as a macro that
- * expands to the module used by the current source file, e.g.
- * #include "vlog.h"
- * #define THIS_MODULE VLM_netlink
+/* Convenience macros for rate-limiting.
* Guaranteed to preserve errno.
*/
#define VLOG_ERR_RL(RL, ...) VLOG_RL(RL, VLL_ERR, __VA_ARGS__)
#define VLOG_INFO_RL(RL, ...) VLOG_RL(RL, VLL_INFO, __VA_ARGS__)
#define VLOG_DBG_RL(RL, ...) VLOG_RL(RL, VLL_DBG, __VA_ARGS__)
+#define VLOG_DROP_ERR(RL) vlog_should_drop(THIS_MODULE, VLL_ERR, RL)
+#define VLOG_DROP_WARN(RL) vlog_should_drop(THIS_MODULE, VLL_WARN, RL)
+#define VLOG_DROP_INFO(RL) vlog_should_drop(THIS_MODULE, VLL_INFO, RL)
+#define VLOG_DROP_DBG(RL) vlog_should_drop(THIS_MODULE, VLL_DBG, RL)
+
/* Command line processing. */
#define VLOG_OPTION_ENUMS OPT_LOG_FILE
#define VLOG_LONG_OPTIONS \