* #define THIS_MODULE VLM_netlink
* Guaranteed to preserve errno.
*/
-#define VLOG_EMER(...) vlog(THIS_MODULE, VLL_EMER, __VA_ARGS__)
-#define VLOG_ERR(...) vlog(THIS_MODULE, VLL_ERR, __VA_ARGS__)
-#define VLOG_WARN(...) vlog(THIS_MODULE, VLL_WARN, __VA_ARGS__)
-#define VLOG_DBG(...) vlog(THIS_MODULE, VLL_DBG, __VA_ARGS__)
+#define VLOG_EMER(...) VLOG(VLL_EMER, __VA_ARGS__)
+#define VLOG_ERR(...) VLOG(VLL_ERR, __VA_ARGS__)
+#define VLOG_WARN(...) VLOG(VLL_WARN, __VA_ARGS__)
+#define VLOG_DBG(...) VLOG(VLL_DBG, __VA_ARGS__)
/* More convenience macros, for testing whether a given level is enabled in
* THIS_MODULE. When constructing a log message is expensive, this enables it
#define VLOG_DBG_RL(RL, ...) \
vlog_rate_limit(THIS_MODULE, VLL_DBG, RL, __VA_ARGS__)
+/* Implementation details. */
+#define VLOG(LEVEL, ...) \
+ do { \
+ if (min_vlog_levels[THIS_MODULE] >= LEVEL) { \
+ vlog(THIS_MODULE, LEVEL, __VA_ARGS__); \
+ } \
+ } while (0)
+extern enum vlog_level min_vlog_levels[VLM_N_MODULES];
+
#endif /* vlog.h */
/* Current log levels. */
static int levels[VLM_N_MODULES][VLF_N_FACILITIES];
+/* For fast checking whether we're logging anything for a given module and
+ * level.*/
+enum vlog_level min_vlog_levels[VLM_N_MODULES];
+
/* Time at which vlog was initialized, in milliseconds. */
static long long int boot_time;
return levels[module][facility];
}
+static void
+update_min_level(enum vlog_module module)
+{
+ enum vlog_level min_level = VLL_EMER;
+ enum vlog_facility facility;
+
+ for (facility = 0; facility < VLF_N_FACILITIES; facility++) {
+ min_level = MAX(min_level, levels[module][facility]);
+ }
+ min_vlog_levels[module] = min_level;
+}
+
static void
set_facility_level(enum vlog_facility facility, enum vlog_module module,
enum vlog_level level)
if (module == VLM_ANY_MODULE) {
for (module = 0; module < VLM_N_MODULES; module++) {
levels[module][facility] = level;
+ update_min_level(module);
}
} else {
levels[module][facility] = level;
+ update_min_level(module);
}
}
bool
vlog_is_enabled(enum vlog_module module, enum vlog_level level)
{
- return (levels[module][VLF_CONSOLE] >= level
- || levels[module][VLF_SYSLOG] >= level);
+ return min_vlog_levels[module] >= level;
}
static const char *