From 886e548ab080896da6760036f38b93ff97fd01a4 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Tue, 16 Jan 2018 01:49:37 +0100 Subject: logging: add ability to log the log-level with API and vty Log the log level string after the category name, if enabled. The default behavior remains unchanged. Change-Id: Ie6be365cfa6aeabdf115bff19bac198440c9adf1 --- src/logging.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/logging.c') diff --git a/src/logging.c b/src/logging.c index e4f3e871..80fc7d2c 100644 --- a/src/logging.c +++ b/src/logging.c @@ -353,6 +353,12 @@ static void _output(struct log_target *target, unsigned int subsys, goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); } + if (target->print_level) { + ret = snprintf(buf + offset, rem, "%s ", log_level_str(level)); + if (ret < 0) + goto err; + OSMO_SNPRINTF_RET(ret, rem, offset, len); + } if (target->print_filename) { ret = snprintf(buf + offset, rem, "<%4.4x> %s:%d ", subsys, file, line); @@ -608,6 +614,17 @@ void log_set_print_category(struct log_target *target, int print_category) target->print_category = print_category; } +/*! Enable or disable printing of the log level name. + * \param[in] target Log target to be affected + * \param[in] print_catname Enable (1) or disable (0) filenames + * + * Print the log level name in front of every log message. + */ +void log_set_print_level(struct log_target *target, int print_level) +{ + target->print_level = (bool)print_level; +} + /*! Set the global log level for a given log target * \param[in] target Log target to be affected * \param[in] log_level New global log level -- cgit v1.2.3