diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2017-01-11 11:54:56 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2017-01-11 11:54:56 +0100 |
commit | f9ab81a9121e377a92d8bd121fe1f5a00c09d4fd (patch) | |
tree | ba8533017950d047fb034a0685a11de90448d548 /include | |
parent | 3624ccc852962ca0dfce7df461ce27fe9e987d02 (diff) | |
parent | f6ba7c8f87d310da5fdfd3fd00eaed3a80c7cfbc (diff) | |
download | ouroboros-f9ab81a9121e377a92d8bd121fe1f5a00c09d4fd.tar.gz ouroboros-f9ab81a9121e377a92d8bd121fe1f5a00c09d4fd.zip |
Merged in dstaesse/ouroboros/be-logs2 (pull request #343)
logs: Comply with C99 standard for variadic macros
Diffstat (limited to 'include')
-rw-r--r-- | include/ouroboros/logs.h | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/include/ouroboros/logs.h b/include/ouroboros/logs.h index ed7c7f8c..4767a6f6 100644 --- a/include/ouroboros/logs.h +++ b/include/ouroboros/logs.h @@ -3,8 +3,9 @@ * * Logging facilities * - * Sander Vrijders <sander.vrijders@intec.ugent.be> + * Sander Vrijders <sander.vrijders@intec.ugent.be> * Francesco Salvestrini <f.salvestrini@nextworks.it> + * Dimitri Staessens <dimitri.staessens@intec.ugent.be> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -26,6 +27,7 @@ #include <unistd.h> #include <stdio.h> +#include <stdbool.h> #ifndef OUROBOROS_PREFIX #error You must define OUROBOROS_PREFIX before including this file @@ -48,38 +50,39 @@ void close_logfile(void); extern FILE * logfile; -#define __LOG(CLR, LVL, FMT, ARGS...) \ +#define __LOG(CLR, FUNC, LVL, ...) \ do { \ if (logfile != NULL) { \ - fprintf(logfile, \ - OUROBOROS_PREFIX "(" LVL "): " \ - FMT ANSI_COLOR_RESET "\n", ##ARGS); \ + fprintf(logfile, OUROBOROS_PREFIX); \ + fprintf(logfile, "(" LVL "): "); \ + if (FUNC) \ + fprintf(logfile, "%s: ", __FUNCTION__); \ + fprintf(logfile, __VA_ARGS__); \ + fprintf(logfile, "\n"); \ fflush(logfile); \ } else { \ - printf(CLR "==%05d== " \ - OUROBOROS_PREFIX "(" LVL "): " \ - FMT ANSI_COLOR_RESET "\n", getpid(), \ - ##ARGS); \ + printf(CLR "==%05d== ", getpid()); \ + printf(OUROBOROS_PREFIX "(" LVL "): "); \ + if (FUNC) \ + printf("%s: ", __FUNCTION__); \ + printf(__VA_ARGS__); \ + printf(ANSI_COLOR_RESET "\n"); \ } \ } while (0) -#define LOG_ERR(FMT, ARGS...) __LOG(ANSI_COLOR_RED, \ - ERROR_CODE, FMT, ##ARGS) -#define LOG_WARN(FMT, ARGS...) __LOG(ANSI_COLOR_YELLOW, \ - WARN_CODE, FMT, ##ARGS) -#define LOG_INFO(FMT, ARGS...) __LOG(ANSI_COLOR_GREEN, \ - INFO_CODE, FMT, ##ARGS) -#define LOG_NI(FMT, ARGS...) __LOG(ANSI_COLOR_BLUE, \ - IMPL_CODE, FMT, ##ARGS) +#define LOG_ERR(...) __LOG(ANSI_COLOR_RED, false, ERROR_CODE, __VA_ARGS__) +#define LOG_WARN(...) __LOG(ANSI_COLOR_YELLOW, false, WARN_CODE, __VA_ARGS__) +#define LOG_INFO(...) __LOG(ANSI_COLOR_GREEN, false, INFO_CODE, __VA_ARGS__) +#define LOG_NI(...) __LOG(ANSI_COLOR_BLUE, false, IMPL_CODE, __VA_ARGS__) #ifdef CONFIG_OUROBOROS_DEBUG -#define LOG_DBG(FMT, ARGS...) __LOG("", DEBUG_CODE, FMT, ##ARGS) +#define LOG_DBG(...) __LOG("", false, DEBUG_CODE, __VA_ARGS__) +#define LOG_DBGF(...) __LOG("", true, DEBUG_CODE, __VA_ARGS__) #else -#define LOG_DBG(FMT, ARGS...) do { } while (0) +#define LOG_DBG(...) do { } while (0) +#define LOG_DBGF(...) do { } while (0) #endif -#define LOG_DBGF(FMT, ARGS...) LOG_DBG("%s: " FMT, __FUNCTION__, ##ARGS) - #define LOG_MISSING LOG_NI("Missing code in %s:%d",__FILE__, __LINE__) #endif |