From ee3dd22b0e5fb415280407af5dedd3f30cfd107e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Wed, 16 Oct 2013 01:44:36 +0200 Subject: [PATCH] Convert logging to use UC_SRC_LOCATION --- include/ucore/logging.h | 13 +++++++------ src/logging.c | 16 +++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/ucore/logging.h b/include/ucore/logging.h index 6bb0956..501a45d 100644 --- a/include/ucore/logging.h +++ b/include/ucore/logging.h @@ -1,5 +1,6 @@ #ifndef UC_LOGGING_H_ #define UC_LOGGING_H_ +#include "utils.h" /** Logging functions. * All logging functions except uc_log_init are thread safe, @@ -268,14 +269,14 @@ int uc_log_reopen_files(void); void uc_log_init(struct uc_log_modules *user_modules); void uc_logf(int log_level, int module, int raw, - const char *file, int line, const char *fmt, ...) - __attribute__((format(printf, 6, 7))); + const char *location, const char *fmt, ...) + __attribute__((format(printf, 5, 6))); #ifdef DEBUG # define UC_DEBUGF(mod, fmt, ...)\ - uc_logf(UC_LL_DEBUG, mod,0 , __FILE__, __LINE__, fmt, ## __VA_ARGS__) + uc_logf(UC_LL_DEBUG, mod,0 , UC_SRC_LOCATION fmt, ## __VA_ARGS__) # define UC_DEBUGFR(mod, fmt, ...)\ - uc_logf(UC_LL_DEBUG, mod,1 , __FILE__, __LINE__, fmt, ## __VA_ARGS__) + uc_logf(UC_LL_DEBUG, mod,1 , UC_SRC_LOCATION, fmt, ## __VA_ARGS__) #else # define UC_DEBUGF(mod, fmt, ...) # define UC_DEBUGFR(mod, fmt, ...) @@ -292,14 +293,14 @@ void uc_logf(int log_level, int module, int raw, * @param ... printf style arguments */ #define UC_LOGF(lvl, mod, fmt, ...) \ - uc_logf(lvl, mod, 0, __FILE__, __LINE__, fmt, ## __VA_ARGS__) + uc_logf(lvl, mod, 0, UC_SRC_LOCATION, fmt, ## __VA_ARGS__) /** Raw logging ,Like UC_LOGF, but only prints the supplied * data, not timestamp, log level etc. */ #define UC_LOGFR(lvl, mod, fmt, ...) \ - uc_logf(lvl, mod, 1, __FILE__, __LINE__, fmt, ## __VA_ARGS__) + uc_logf(lvl, mod, 1, UC_SRC_LOCATION, fmt, ## __VA_ARGS__) #ifdef __cplusplus } diff --git a/src/logging.c b/src/logging.c index 85146e8..248e548 100644 --- a/src/logging.c +++ b/src/logging.c @@ -42,8 +42,7 @@ struct uc_log_args { struct uc_log_destination *dest; const struct uc_log_module *module; int log_level; - const char *file; - int line; + const char *location; int raw; }; @@ -415,9 +414,9 @@ static inline void uc_vlog_file(const struct uc_log_args *args, const char *fmt, time_buf[sizeof time_buf -1] = 0; if (dest->log_location) { - fprintf(dest->type.file.file, "[%-7s] %s %s:%d [%s] : ", - uc_ll_2_str(args->log_level), time_buf, args->file, - args->line, args->module->short_name); + fprintf(dest->type.file.file, "[%-7s] %s %s [%s] : ", + uc_ll_2_str(args->log_level), time_buf, + args->location, args->module->short_name); } else { fprintf(dest->type.file.file, "[%-7s] %s [%s]: ", uc_ll_2_str(args->log_level), time_buf, args->module->short_name); @@ -446,7 +445,7 @@ static inline void uc_vlog_syslog(const struct uc_log_args *args, const char *fm buf[0] = 0; if (dest->log_location) { - rc = snprintf(buf, sizeof buf, "%s:%d ", args->file, args->line); + rc = snprintf(buf, sizeof buf, "%s ", args->location); if (rc < 0) goto log; offset += rc; @@ -543,7 +542,7 @@ void uc_log_destination_set_mask( } void uc_logf(int log_level, int module, int raw, - const char *file, int line, const char *fmt, ...) + const char *location, const char *fmt, ...) { va_list ap; struct uc_log_destination *dest; @@ -581,8 +580,7 @@ void uc_logf(int log_level, int module, int raw, .dest = dest, .module = log_module, .log_level = log_level, - .file = file, - .line = line, + .location = location, .raw = raw };