mirror of https://gerrit.osmocom.org/libosmocore
Merge branch 'sysmocom/shared/log-speed'
This commit is contained in:
commit
5dd3f1dd67
|
@ -19,8 +19,18 @@
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define DEBUGP(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 0, fmt, ## args)
|
#define DEBUGP(ss, fmt, args...) \
|
||||||
#define DEBUGPC(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 1, fmt, ## args)
|
do { \
|
||||||
|
if (log_check_level(ss, LOGL_DEBUG)) \
|
||||||
|
logp(ss, __FILE__, __LINE__, 0, fmt, ## args); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define DEBUGPC(ss, fmt, args...) \
|
||||||
|
do { \
|
||||||
|
if (log_check_level(ss, LOGL_DEBUG)) \
|
||||||
|
logp(ss, __FILE__, __LINE__, 1, fmt, ## args); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define DEBUGP(xss, fmt, args...)
|
#define DEBUGP(xss, fmt, args...)
|
||||||
#define DEBUGPC(ss, fmt, args...)
|
#define DEBUGPC(ss, fmt, args...)
|
||||||
|
@ -39,7 +49,10 @@ void logp(int subsys, const char *file, int line, int cont, const char *format,
|
||||||
* \param[in] args variable argument list
|
* \param[in] args variable argument list
|
||||||
*/
|
*/
|
||||||
#define LOGP(ss, level, fmt, args...) \
|
#define LOGP(ss, level, fmt, args...) \
|
||||||
logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args)
|
do { \
|
||||||
|
if (log_check_level(ss, level)) \
|
||||||
|
logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/*! \brief Continue a log message through the Osmocom logging framework
|
/*! \brief Continue a log message through the Osmocom logging framework
|
||||||
* \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
|
* \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
|
||||||
|
@ -48,7 +61,10 @@ void logp(int subsys, const char *file, int line, int cont, const char *format,
|
||||||
* \param[in] args variable argument list
|
* \param[in] args variable argument list
|
||||||
*/
|
*/
|
||||||
#define LOGPC(ss, level, fmt, args...) \
|
#define LOGPC(ss, level, fmt, args...) \
|
||||||
logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args)
|
do { \
|
||||||
|
if (log_check_level(ss, level)) \
|
||||||
|
logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/*! \brief different log levels */
|
/*! \brief different log levels */
|
||||||
#define LOGL_DEBUG 1 /*!< \brief debugging information */
|
#define LOGL_DEBUG 1 /*!< \brief debugging information */
|
||||||
|
@ -198,6 +214,7 @@ void logp2(int subsys, unsigned int level, const char *file,
|
||||||
int line, int cont, const char *format, ...)
|
int line, int cont, const char *format, ...)
|
||||||
__attribute__ ((format (printf, 6, 7)));
|
__attribute__ ((format (printf, 6, 7)));
|
||||||
int log_init(const struct log_info *inf, void *talloc_ctx);
|
int log_init(const struct log_info *inf, void *talloc_ctx);
|
||||||
|
int log_check_level(int subsys, unsigned int level);
|
||||||
|
|
||||||
/* context management */
|
/* context management */
|
||||||
void log_reset_context(void);
|
void log_reset_context(void);
|
||||||
|
|
|
@ -310,46 +310,61 @@ err:
|
||||||
target->output(target, level, buf);
|
target->output(target, level, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int map_subsys(int subsys)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* 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 */
|
/*! \brief vararg version of logging function */
|
||||||
void osmo_vlogp(int subsys, int level, const char *file, int line,
|
void osmo_vlogp(int subsys, int level, const char *file, int line,
|
||||||
int cont, const char *format, va_list ap)
|
int cont, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
struct log_target *tar;
|
struct log_target *tar;
|
||||||
|
|
||||||
if (subsys < 0)
|
subsys = map_subsys(subsys);
|
||||||
subsys = subsys_lib2index(subsys);
|
|
||||||
|
|
||||||
if (subsys > osmo_log_info->num_cat)
|
|
||||||
subsys = DLGLOBAL;
|
|
||||||
|
|
||||||
llist_for_each_entry(tar, &osmo_log_target_list, entry) {
|
llist_for_each_entry(tar, &osmo_log_target_list, entry) {
|
||||||
struct log_category *category;
|
|
||||||
int output = 0;
|
int output = 0;
|
||||||
va_list bp;
|
va_list bp;
|
||||||
|
|
||||||
category = &tar->categories[subsys];
|
if (!check_log_to_target(tar, subsys, level))
|
||||||
/* 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)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* 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)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* According to the manpage, vsnprintf leaves the value of ap
|
/* 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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/*! @} */
|
/*! @} */
|
||||||
|
|
|
@ -30,6 +30,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
static int filter_called = 0;
|
static int filter_called = 0;
|
||||||
|
static int select_output = 0;
|
||||||
|
|
||||||
static const struct log_info_cat default_categories[] = {
|
static const struct log_info_cat default_categories[] = {
|
||||||
[DRLL] = {
|
[DRLL] = {
|
||||||
|
@ -56,7 +57,7 @@ static int test_filter(const struct log_context *ctx, struct log_target *target)
|
||||||
{
|
{
|
||||||
filter_called += 1;
|
filter_called += 1;
|
||||||
/* omit everything */
|
/* omit everything */
|
||||||
return 0;
|
return select_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct log_info log_info = {
|
const struct log_info log_info = {
|
||||||
|
@ -77,17 +78,33 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
log_parse_category_mask(stderr_target, "DRLL:DCC");
|
log_parse_category_mask(stderr_target, "DRLL:DCC");
|
||||||
log_parse_category_mask(stderr_target, "DRLL");
|
log_parse_category_mask(stderr_target, "DRLL");
|
||||||
|
|
||||||
|
select_output = 0;
|
||||||
|
|
||||||
DEBUGP(DCC, "You should not see this\n");
|
DEBUGP(DCC, "You should not see this\n");
|
||||||
|
if (log_check_level(DMM, LOGL_DEBUG) != 0)
|
||||||
|
fprintf(stderr, "log_check_level did not catch this case\n");
|
||||||
|
|
||||||
log_parse_category_mask(stderr_target, "DRLL:DCC");
|
log_parse_category_mask(stderr_target, "DRLL:DCC");
|
||||||
DEBUGP(DRLL, "You should see this\n");
|
DEBUGP(DRLL, "You should see this\n");
|
||||||
|
OSMO_ASSERT(log_check_level(DRLL, LOGL_DEBUG) != 0);
|
||||||
DEBUGP(DCC, "You should see this\n");
|
DEBUGP(DCC, "You should see this\n");
|
||||||
|
OSMO_ASSERT(log_check_level(DCC, LOGL_DEBUG) != 0);
|
||||||
DEBUGP(DMM, "You should not see this\n");
|
DEBUGP(DMM, "You should not see this\n");
|
||||||
|
|
||||||
|
OSMO_ASSERT(log_check_level(DMM, LOGL_DEBUG) == 0);
|
||||||
OSMO_ASSERT(filter_called == 0);
|
OSMO_ASSERT(filter_called == 0);
|
||||||
|
|
||||||
log_set_all_filter(stderr_target, 0);
|
log_set_all_filter(stderr_target, 0);
|
||||||
DEBUGP(DRLL, "You should not see this and filter is called\n");
|
DEBUGP(DRLL, "You should not see this and filter is called\n");
|
||||||
OSMO_ASSERT(filter_called == 1);
|
OSMO_ASSERT(filter_called == 1);
|
||||||
|
OSMO_ASSERT(log_check_level(DRLL, LOGL_DEBUG) == 0);
|
||||||
|
OSMO_ASSERT(filter_called == 2);
|
||||||
|
|
||||||
|
DEBUGP(DRLL, "You should not see this\n");
|
||||||
|
OSMO_ASSERT(filter_called == 3);
|
||||||
|
select_output = 1;
|
||||||
|
DEBUGP(DRLL, "You should see this\n");
|
||||||
|
OSMO_ASSERT(filter_called == 5); /* called twice on output */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
[1;31mYou should see this
|
[1;31mYou should see this
|
||||||
[0;m[1;32mYou should see this
|
[0;m[1;32mYou should see this
|
||||||
|
[0;m[1;31mYou should see this
|
||||||
[0;m
|
[0;m
|
Loading…
Reference in New Issue