This allows the user of ell to limit the logging verbosity to whatever value they want by calling l_log_set_max_level. The current behavior of no limit is maintained. --- ell/log.c | 16 ++++++++++++++++ ell/log.h | 1 + 2 files changed, 17 insertions(+) diff --git a/ell/log.c b/ell/log.c index 05af3e5..89e4ffc 100644 --- a/ell/log.c +++ b/ell/log.c @@ -37,6 +37,7 @@ #include "queue.h" #include "log.h" #include "private.h" +#include "useful.h" struct debug_section { struct l_debug_desc *start; @@ -67,6 +68,7 @@ static l_log_func_t log_func = log_null; static const char *log_ident = ""; static int log_fd = -1; static unsigned long log_pid; +static int max_log_level = L_LOG_DEBUG; static inline void close_log(void) { @@ -275,6 +277,17 @@ LIB_EXPORT void l_log_set_journal(void) log_func = log_journal; } +/** + * l_log_set_max_level: + * @priority: max level + * + * Set the maximum logging level. + */ +LIB_EXPORT void l_log_set_max_level(int priority) +{ + max_log_level = priority; +} + /** * l_log_with_location: * @priority: priority level @@ -292,6 +305,9 @@ LIB_EXPORT void l_log_with_location(int priority, { va_list ap; + if (unlikely(priority > max_log_level)) + return; + va_start(ap, format); log_func(priority, file, line, func, format, ap); va_end(ap); diff --git a/ell/log.h b/ell/log.h index 9ae40c0..3fc3867 100644 --- a/ell/log.h +++ b/ell/log.h @@ -44,6 +44,7 @@ void l_log_set_null(void); void l_log_set_stderr(void); void l_log_set_syslog(void); void l_log_set_journal(void); +void l_log_set_max_level(int priority); void l_log_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) -- 2.25.1