From: Ben Pfaff Date: Mon, 13 Sep 2010 20:29:57 +0000 (-0700) Subject: vlog: Add VLOG_WARN_ONCE() and similar macros. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5136364f41b74de00f86873a6f5be4c8a19cb5ad;p=openvswitch vlog: Add VLOG_WARN_ONCE() and similar macros. --- diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 2c688e3a..ec8a952b 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -731,11 +731,7 @@ get_major(const char *target) return major; } } else { - static bool warned; - if (!warned) { - VLOG_WARN("%s:%d: syntax error", fn, ln); - } - warned = true; + VLOG_WARN_ONCE("%s:%d: syntax error", fn, ln); } } diff --git a/lib/vlog.h b/lib/vlog.h index 03f17ea5..a4e143c1 100644 --- a/lib/vlog.h +++ b/lib/vlog.h @@ -181,6 +181,12 @@ void vlog_rate_limit(const struct vlog_module *, enum vlog_level, #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) +/* Macros for logging at most once per execution. */ +#define VLOG_ERR_ONCE(...) VLOG_ONCE(VLL_ERR, __VA_ARGS__) +#define VLOG_WARN_ONCE(...) VLOG_ONCE(VLL_WARN, __VA_ARGS__) +#define VLOG_INFO_ONCE(...) VLOG_ONCE(VLL_INFO, __VA_ARGS__) +#define VLOG_DBG_ONCE(...) VLOG_ONCE(VLL_DBG, __VA_ARGS__) + /* Command line processing. */ #define VLOG_OPTION_ENUMS OPT_LOG_FILE #define VLOG_LONG_OPTIONS \ @@ -208,6 +214,15 @@ void vlog_usage(void); vlog_rate_limit(THIS_MODULE, LEVEL, RL, __VA_ARGS__); \ } \ } while (0) +#define VLOG_ONCE(LEVEL, ...) \ + do { \ + static bool already_logged; \ + if (!already_logged) { \ + already_logged = true; \ + vlog(THIS_MODULE, LEVEL, __VA_ARGS__); \ + } \ + } while (0) + #define VLOG_DEFINE_MODULE__(MODULE) \ struct vlog_module VLM_##MODULE = \ { \