aboutsummaryrefslogtreecommitdiffstats
path: root/src/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/logging.c')
-rw-r--r--src/logging.c95
1 files changed, 66 insertions, 29 deletions
diff --git a/src/logging.c b/src/logging.c
index 876964ae..1c9c6634 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -310,46 +310,61 @@ err:
target->output(target, level, buf);
}
-/*! \brief vararg version of logging function */
-void osmo_vlogp(int subsys, int level, const char *file, int line,
- int cont, const char *format, va_list ap)
+static inline int map_subsys(int subsys)
{
- struct log_target *tar;
-
if (subsys < 0)
subsys = subsys_lib2index(subsys);
if (subsys > osmo_log_info->num_cat)
subsys = DLGLOBAL;
+ return subsys;
+}
- llist_for_each_entry(tar, &osmo_log_target_list, entry) {
- struct log_category *category;
- int output = 0;
- va_list bp;
+static inline int check_log_to_target(struct log_target *tar, int subsys, int level)
+{
+ struct log_category *category;
- category = &tar->categories[subsys];
- /* subsystem is not supposed to be logged */
- if (!category->enabled)
- continue;
+ category = &tar->categories[subsys];
- /* Check the global log level */
- if (tar->loglevel != 0 && level < tar->loglevel)
- continue;
+ /* subsystem is not supposed to be logged */
+ if (!category->enabled)
+ return 0;
- /* Check the category log level */
- if (tar->loglevel == 0 && category->loglevel != 0 &&
- level < category->loglevel)
- continue;
+ /* Check the global log level */
+ if (tar->loglevel != 0 && level < tar->loglevel)
+ return 0;
+
+ /* Check the category log level */
+ if (tar->loglevel == 0 && category->loglevel != 0 &&
+ level < category->loglevel)
+ return 0;
+
+ /* Apply filters here... if that becomes messy we will
+ * need to put filters in a list and each filter will
+ * say stop, continue, output */
+ if ((tar->filter_map & LOG_FILTER_ALL) != 0)
+ return 1;
+
+ if (osmo_log_info->filter_fn)
+ return osmo_log_info->filter_fn(&log_context, tar);
+
+ /* TODO: Check the filter/selector too? */
+ return 1;
+}
+
+/*! \brief vararg version of logging function */
+void osmo_vlogp(int subsys, int level, const char *file, int line,
+ int cont, const char *format, va_list ap)
+{
+ struct log_target *tar;
- /* Apply filters here... if that becomes messy we will
- * need to put filters in a list and each filter will
- * say stop, continue, output */
- if ((tar->filter_map & LOG_FILTER_ALL) != 0)
- output = 1;
- else if (osmo_log_info->filter_fn)
- output = osmo_log_info->filter_fn(&log_context,
- tar);
- if (!output)
+ subsys = map_subsys(subsys);
+
+ llist_for_each_entry(tar, &osmo_log_target_list, entry) {
+ int output = 0;
+ va_list bp;
+
+ if (!check_log_to_target(tar, subsys, level))
continue;
/* According to the manpage, vsnprintf leaves the value of ap
@@ -865,4 +880,26 @@ int log_init(const struct log_info *inf, void *ctx)
return 0;
}
+/*! \brief Check whether a log entry will be generated.
+ * \returns != 0 if a log entry might get generated by at least one target */
+int log_check_level(int subsys, unsigned int level)
+{
+ struct log_target *tar;
+
+ subsys = map_subsys(subsys);
+
+ /* TODO: The following could/should be cached (update on config) */
+
+ llist_for_each_entry(tar, &osmo_log_target_list, entry) {
+ if (!check_log_to_target(tar, subsys, level))
+ continue;
+
+ /* This might get logged (ignoring filters) */
+ return 1;
+ }
+
+ /* We are sure, that this will not be logged. */
+ return 0;
+}
+
/*! @} */