From 032e50e1cda4b299cde391c83e7eeb440d7db3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sat, 1 Jun 2013 23:45:14 +0200 Subject: [PATCH] Remove setting log level for a module, implement setting log level for a destination --- include/ucore/logging.h | 15 +++++++-------- src/logging.c | 28 +++++++++------------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/include/ucore/logging.h b/include/ucore/logging.h index 81d41d3..d523dce 100644 --- a/include/ucore/logging.h +++ b/include/ucore/logging.h @@ -175,6 +175,13 @@ void uc_log_add_destination(struct uc_log_destination *dest); */ void uc_log_remove_destination(struct uc_log_destination *dest); +/** Change the log level of a destination.. + * + * @param dest destination for which to set the log level + * @param level The new log level + */ +void uc_log_destination_set_loglevel(struct uc_log_destination *dest, enum UC_LOG_LEVEL level); + /** Remove and free a destination. * This frees the memory allocated to the destination. For * UC_LDEST_FILE the log file is closed. @@ -187,14 +194,6 @@ void uc_log_remove_destination(struct uc_log_destination *dest); */ void uc_log_delete_destination(struct uc_log_destination *dest); -/** Change the log level of a module. - * - * @param module The module to change, matched against the id member of a struct uc_log_module - * @param level The log level for this module - * - * @return 0 on success, non-zero if the module was not found. - */ -int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level); /** Closes and re-opens all the UC_LDEST_FILE log destinations. * Intended for use when a log file is rotated externally. diff --git a/src/logging.c b/src/logging.c index 3970b56..9e64fce 100644 --- a/src/logging.c +++ b/src/logging.c @@ -294,6 +294,15 @@ void uc_log_delete_destination(struct uc_log_destination *dest) pthread_mutex_unlock(&g_log_lock); } +void uc_log_destination_set_loglevel(struct uc_log_destination *dest, enum UC_LOG_LEVEL level) +{ + pthread_mutex_lock(&g_log_lock); + + dest->log_level = level; + + pthread_mutex_unlock(&g_log_lock); +} + static int uc_log_reopen_file(struct uc_log_destination *dest) { int rc = 0; @@ -337,25 +346,6 @@ void uc_log_init(struct uc_log_modules *user_modules) g_modules = *user_modules; } -int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level) -{ - int rc = -1; - int i; - - pthread_mutex_lock(&g_log_lock); - - for (i = 0; i < g_modules.cnt; i++) { - if (g_modules.mods[i].id == module) { - g_modules.mods[i].log_level = level; - rc = 0; - break; - } - } - - pthread_mutex_unlock(&g_log_lock); - - return rc; -} static inline void uc_vlog_file(const struct uc_log_args *args, const char *fmt, va_list ap) {