summaryrefslogtreecommitdiffstats
path: root/src/vlib/log.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2023-05-26 19:06:10 +0000
committerFlorin Coras <florin.coras@gmail.com>2023-05-27 17:41:28 +0000
commitbf179a91d8d224c64d08643a2bb52580f68ce96b (patch)
treea4ea1a8960d5da124e28920921183171ee48fe15 /src/vlib/log.h
parent2355e4973365b0ea3f14737f894636973e656b16 (diff)
vlib: add vlib_log_is_enabled
Type: improvement Change-Id: I052e0d56cc6d89cd66c83a9bb81e2273d396d510 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/log.h')
-rw-r--r--src/vlib/log.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/vlib/log.h b/src/vlib/log.h
index 0ded4a8ec84..d9eb841a9a3 100644
--- a/src/vlib/log.h
+++ b/src/vlib/log.h
@@ -149,6 +149,34 @@ __vlib_add_log_registration_##x (void) \
} \
__VA_ARGS__ vlib_log_class_registration_t x
+static_always_inline vlib_log_class_data_t *
+vnet_log_get_class_data (vlib_log_class_t ci)
+{
+ vlib_log_main_t *lm = &log_main;
+ return vec_elt_at_index (lm->classes, (ci >> 16));
+}
+
+static_always_inline vlib_log_subclass_data_t *
+vlib_log_get_subclass_data (vlib_log_class_t ci)
+{
+ vlib_log_class_data_t *c = vnet_log_get_class_data (ci);
+ return vec_elt_at_index (c->subclasses, (ci & 0xffff));
+}
+
+static_always_inline int
+vlib_log_is_enabled (vlib_log_level_t level, vlib_log_class_t class)
+{
+ vlib_log_subclass_data_t *sc = vlib_log_get_subclass_data (class);
+
+ if (level <= sc->level && sc->level != VLIB_LOG_LEVEL_DISABLED)
+ return 1;
+
+ if (level <= sc->syslog_level && sc->syslog_level != VLIB_LOG_LEVEL_DISABLED)
+ return 1;
+
+ return 0;
+}
+
#endif /* included_vlib_log_h */
/*