From 67e0aea25850b8286f750e6458e5de741e6cb3b5 Mon Sep 17 00:00:00 2001 From: oharboe Date: Fri, 29 Feb 2008 11:16:38 +0000 Subject: Summary: passing of variable argument list reduced, strings sent to logging are now formatted just once - more efficient. As a result, ugly string malloc+strcpy are not needed anymore. git-svn-id: svn://svn.berlios.de/openocd/trunk@386 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/helper/log.h | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'src/helper/log.h') diff --git a/src/helper/log.h b/src/helper/log.h index a53b7f5..c407844 100644 --- a/src/helper/log.h +++ b/src/helper/log.h @@ -47,7 +47,7 @@ enum log_levels extern void log_printf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...) __attribute__ ((format (printf, 5, 6))); -extern void log_printfnl(enum log_levels level, const char *file, int line, +extern void log_printf_lf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...) __attribute__ ((format (printf, 5, 6))); extern int log_register_commands(struct command_context_s *cmd_ctx); @@ -55,13 +55,13 @@ extern int log_init(struct command_context_s *cmd_ctx); extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output); typedef void (*log_callback_fn)(void *priv, const char *file, int line, - const char *function, const char *format, va_list args); + const char *function, const char *string); typedef struct log_callback_s { - log_callback_fn fn; + log_callback_fn fn; void *priv; - struct log_callback_s *next; + struct log_callback_s *next; } log_callback_t; extern int log_add_callback(log_callback_fn fn, void *priv); @@ -76,44 +76,28 @@ extern int debug_level; #define DEBUG(expr ...) \ - do { if (debug_level >= LOG_DEBUG) \ - log_printfnl (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) + log_printf_lf (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr) #define INFO(expr ...) \ - do { if (debug_level >= LOG_INFO) \ - log_printfnl (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) + log_printf_lf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr) -#define INFO_SAMELINE(expr ...) \ - do { if (debug_level >= LOG_INFO) \ - log_printf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) +#define INFO_N(expr ...) \ + log_printf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr) #define WARNING(expr ...) \ - do { \ - log_printfnl (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) + log_printf_lf (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr) #define ERROR(expr ...) \ - do { \ - log_printfnl (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) + log_printf_lf (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr) #define USER(expr ...) \ - do { \ - log_printfnl (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) + log_printf_lf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr) -#define USER_SAMELINE(expr ...) \ - do { \ - log_printf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) +#define USER_N(expr ...) \ + log_printf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr) #define OUTPUT(expr ...) \ - do { \ - log_printf (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr); \ - } while(0) + log_printf (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr) /* general failures -- cgit v1.1