summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-02-29 14:34:34 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-02-29 14:34:34 +0100
commit5dd3f1dd67a41fb46f2fcb6b58068525cda0a8a0 (patch)
tree1f1e99928a86f18a0b073da7fb83197c154e97ad /src
parentf20f5fd5085879624fb6de1e5b9b5ad435ea0500 (diff)
parent79599acd663f7c488560d72d63f4e29587fc63a2 (diff)
Merge branch 'sysmocom/shared/log-speed'
Diffstat (limited to 'src')
-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;
+}
+
/*! @} */