summaryrefslogtreecommitdiffstats
path: root/src/logging.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-17 16:35:27 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-22 16:08:38 +0000
commit812ba6dc63a75c39678dd3fe652768e76bf63183 (patch)
tree760a4307fe5a1de5d30f6115b6801018936c15b2 /src/logging.c
parentbd9de2f66f82db66bbbe7e7df54bf8fee8e1a8ae (diff)
logging: centrally define ctx and filter indexes
It is too easy for calling code to use the same filter and context indexes for different filters and structs. For example, openbsc's IMSI filter and libgb's GPRS_BVC filter both fall on index 1 even though there are plenty more indexes to choose from. To alleviate this, have one central definition here, sort of like ports.h does for VTY and CTRL port numbers. Add static asserts to make sure the indexes fit in the available array and bit mask space. Calling code like openbsc.git and osmo-pcu need adjustments and/or should move to using these enum values instead of their local definitions. Taking this opportunity to also prepare for a split of struct gsm_subscriber in openbsc into bsc_subsciber and vlr_subscriber with appropriate separate filter index constants for both subscriber types. Include previous LOG_FILTER_ALL in the LOGGING_FILTER_* enum, and replace its use by (1 << LOGGING_FILTER_ALL). Change-Id: I5c343630020f4b108099696fd96c2111614c8067
Diffstat (limited to 'src/logging.c')
-rw-r--r--src/logging.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/logging.c b/src/logging.c
index 9b7d6f45..b09d6845 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -48,6 +48,13 @@
#include <osmocom/vty/logging.h> /* for LOGGING_STR. */
+osmo_static_assert(_LOGGING_CTX_COUNT <= ARRAY_SIZE(((struct log_context*)NULL)->ctx),
+ enum_logging_ctx_items_fit_in_struct_log_context);
+osmo_static_assert(_LOGGING_FILTER_COUNT <= ARRAY_SIZE(((struct log_target*)NULL)->filter_data),
+ enum_logging_filters_fit_in_log_target_filter_data);
+osmo_static_assert(_LOGGING_FILTER_COUNT <= 8*sizeof(((struct log_target*)NULL)->filter_map),
+ enum_logging_filters_fit_in_log_target_filter_map);
+
struct log_info *osmo_log_info;
static struct log_context log_context;
@@ -374,7 +381,7 @@ static inline int check_log_to_target(struct log_target *tar, int subsys, int le
/* 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)
+ if ((tar->filter_map & (1 << LOGGING_FILTER_ALL)) != 0)
return 1;
if (osmo_log_info->filter_fn)
@@ -492,20 +499,20 @@ int log_set_context(uint8_t ctx_nr, void *value)
return 0;
}
-/*! \brief Enable the \ref LOG_FILTER_ALL log filter
+/*! \brief Enable the \ref LOGGING_FILTER_ALL log filter
* \param[in] target Log target to be affected
* \param[in] all enable (1) or disable (0) the ALL filter
*
- * When the \ref LOG_FILTER_ALL filter is enabled, all log messages will
- * be printed. It acts as a wildcard. Setting it to \a 1 means there
- * is no filtering.
+ * When the \ref LOGGING_FILTER_ALL filter is enabled, all log messages will be
+ * printed. It acts as a wildcard. Setting it to \a 1 means there is no
+ * filtering.
*/
void log_set_all_filter(struct log_target *target, int all)
{
if (all)
- target->filter_map |= LOG_FILTER_ALL;
+ target->filter_map |= (1 << LOGGING_FILTER_ALL);
else
- target->filter_map &= ~LOG_FILTER_ALL;
+ target->filter_map &= ~(1 << LOGGING_FILTER_ALL);
}
/*! \brief Enable or disable the use of colored output