From f8116643af85768dc3222942602f68e9754b188e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Wed, 5 Jun 2013 21:09:35 +0200 Subject: [PATCH] Add uc_log_destination_set_log_location, fix signed/unsigned use --- include/ucore/logging.h | 7 +++++++ src/logging.c | 24 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/ucore/logging.h b/include/ucore/logging.h index d523dce..b018bd4 100644 --- a/include/ucore/logging.h +++ b/include/ucore/logging.h @@ -182,6 +182,13 @@ void uc_log_remove_destination(struct uc_log_destination *dest); */ void uc_log_destination_set_loglevel(struct uc_log_destination *dest, enum UC_LOG_LEVEL level); +/** Change whether to log the location (file/line no.) of logging + * output on a destination, + * + * @param dest log destination to change + * @param log_location 1=log the locaton, 0=don't log the location + */ +void uc_log_destination_set_log_location(struct uc_log_destination *dest, int log_location); /** Remove and free a destination. * This frees the memory allocated to the destination. For * UC_LDEST_FILE the log file is closed. diff --git a/src/logging.c b/src/logging.c index 8015cc5..a34a8a4 100644 --- a/src/logging.c +++ b/src/logging.c @@ -80,15 +80,15 @@ static const char *const g_debug_levels[] = { inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l) { - if (l >= 0 && l < (int)ARRAY_SIZE(g_debug_levels)) { + if (l < ARRAY_SIZE(g_debug_levels)) { return g_debug_levels[l]; } else { return "???"; } } -//returns -1 if the string is not a known log level -static enum UC_LOG_LEVEL uc_str_2_ll(const char *str) +//returns if the string is not a known log level +static int uc_str_2_ll(const char *str) { size_t i; @@ -313,6 +313,9 @@ void uc_log_delete_destination(struct uc_log_destination *dest) void uc_log_destination_set_loglevel(struct uc_log_destination *dest, enum UC_LOG_LEVEL level) { + if (dest == NULL) + return; + pthread_mutex_lock(&g_log_lock); dest->log_level = level; @@ -320,10 +323,25 @@ void uc_log_destination_set_loglevel(struct uc_log_destination *dest, enum UC_LO pthread_mutex_unlock(&g_log_lock); } +void uc_log_destination_set_log_location(struct uc_log_destination *dest, int log_location) +{ + if (dest == NULL) + return; + + pthread_mutex_lock(&g_log_lock); + + dest->log_location = log_location; + + pthread_mutex_unlock(&g_log_lock); +} + static int uc_log_reopen_file(struct uc_log_destination *dest) { int rc = 0; + if (dest == NULL) + return -1; + if (dest->type.file.file != NULL) { fclose(dest->type.file.file); dest->type.file.file = NULL;