log: Add a max_log_level and limit l_log
Michael Johnson
PATCH 1/1 log: Add a max_log_level and limit l_log
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(+)
ell/log.c +16 -0
@@ -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);
ell/log.h +1 -0
@@ -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, ...)
Signature · 1 line
2.25.1