From: Ben Pfaff Date: Thu, 3 Apr 2008 15:28:04 +0000 (-0700) Subject: Add vlog functions and macros for testing whether a module and level are enabled. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a0a1dbe4c67a43173a421db7364f9f79fd064c5;p=openvswitch Add vlog functions and macros for testing whether a module and level are enabled. --- diff --git a/include/vlog.h b/include/vlog.h index 63a0c412..7d15ad28 100644 --- a/include/vlog.h +++ b/include/vlog.h @@ -98,6 +98,7 @@ enum vlog_level vlog_get_level(enum vlog_module, enum vlog_facility); void vlog_set_levels(enum vlog_module, enum vlog_facility, enum vlog_level); char *vlog_set_levels_from_string(const char *); char *vlog_get_levels(void); +bool vlog_is_enabled(enum vlog_module, enum vlog_level); void vlog_set_verbosity(const char *arg); /* Function for actual logging. */ @@ -117,4 +118,12 @@ void vlog(enum vlog_module, enum vlog_level, const char *format, ...) #define VLOG_WARN(...) vlog(THIS_MODULE, VLL_WARN, __VA_ARGS__) #define VLOG_DBG(...) vlog(THIS_MODULE, 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 + * to be skipped. */ +#define VLOG_IS_EMER_ENABLED() true +#define VLOG_IS_ERR_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_EMER) +#define VLOG_IS_WARN_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_WARN) +#define VLOG_IS_DBG_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_DBG) + #endif /* vlog.h */ diff --git a/lib/vlog.c b/lib/vlog.c index 3c977bf6..63162723 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -277,6 +277,16 @@ vlog_get_levels(void) return ds_cstr(&s); } +/* Returns true if a log message emitted for the given 'module' and 'level' + * would cause some log output, false if that module and level are completely + * disabled. */ +bool +vlog_is_enabled(enum vlog_module module, enum vlog_level level) +{ + return (levels[module][VLF_CONSOLE] >= level + || levels[module][VLF_SYSLOG] >= level); +} + /* Writes 'message' to the log at the given 'level' and as coming from the * given 'module'. *