aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-12-21 14:45:16 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-12-21 15:15:45 +0100
commit87215d5bd97b0ba9249825dcbfb4d449f42b5a15 (patch)
treea9a0678c73f96bf70b65b0295a744a616db1ab85
parentf96826f2039a4a794f86ea3d81d3a728a6450847 (diff)
logging: Remove some code duplication
Extract the mapping of the subsystem number and the checking for the loglevel to a inline method that is shared between the new and old.
-rw-r--r--src/logging.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/logging.c b/src/logging.c
index c7b19999..7db7101e 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -310,35 +310,52 @@ 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;
+}
+
+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)
+ return 0;
+
+ /* 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;
+
+ /* 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;
+
+ subsys = map_subsys(subsys);
llist_for_each_entry(tar, &osmo_log_target_list, entry) {
- struct log_category *category;
int output = 0;
va_list bp;
- category = &tar->categories[subsys];
- /* subsystem is not supposed to be logged */
- if (!category->enabled)
- continue;
-
- /* Check the global log level */
- if (tar->loglevel != 0 && level < tar->loglevel)
- continue;
-
- /* Check the category log level */
- if (tar->loglevel == 0 && category->loglevel != 0 &&
- level < category->loglevel)
+ if (!check_log_to_target(tar, subsys, level))
continue;
/* Apply filters here... if that becomes messy we will
@@ -871,29 +888,12 @@ int log_check_level(int subsys, unsigned int level)
{
struct log_target *tar;
- if (subsys < 0)
- subsys = subsys_lib2index(subsys);
-
- if (subsys > osmo_log_info->num_cat)
- subsys = DLGLOBAL;
+ subsys = map_subsys(subsys);
/* TODO: The following could/should be cached (update on config) */
llist_for_each_entry(tar, &osmo_log_target_list, entry) {
- struct log_category *category;
-
- category = &tar->categories[subsys];
- /* subsystem is not supposed to be logged */
- if (!category->enabled)
- continue;
-
- /* Check the global log level */
- if (tar->loglevel != 0 && level < tar->loglevel)
- continue;
-
- /* Check the category log level */
- if (tar->loglevel == 0 && category->loglevel != 0 &&
- level < category->loglevel)
+ if (!check_log_to_target(tar, subsys, level))
continue;
/* This might get logged (ignoring filters) */