vlog: Add VLOG_WARN_ONCE() and similar macros.
authorBen Pfaff <blp@nicira.com>
Mon, 13 Sep 2010 20:29:57 +0000 (13:29 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 23 Sep 2010 18:45:34 +0000 (11:45 -0700)
lib/dpif-linux.c
lib/vlog.h

index 2c688e3af31fabfa4cc2032a0109850862a0e48a..ec8a952b3d1611773ca410cb47edbad0f78cb8dd 100644 (file)
@@ -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);
         }
     }
 
index 03f17ea5630d10a6cecbf4e1b85464732d81b465..a4e143c1b2dca64bd593a34859bff39fa416bd9f 100644 (file)
@@ -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 =                               \
         {                                                               \