From 24aec994f96a48110bf78665683bff9656778fd3 Mon Sep 17 00:00:00 2001 From: wonder-mice Date: Tue, 26 Apr 2016 18:48:14 -0700 Subject: [PATCH] Add call site size tests for conditionals --- tests/CMakeLists.txt | 4 + tests/test_call_site_size_censoring.c | 34 +++ tests/test_call_site_size_conditional.c | 40 ++++ tests/zf_log.h.master | 275 +++++++++++++++++++----- 4 files changed, 299 insertions(+), 54 deletions(-) create mode 100644 tests/test_call_site_size_censoring.c create mode 100644 tests/test_call_site_size_conditional.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f1ab00e..282e853 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -150,3 +150,7 @@ endfunction() add_code_size_test(test_call_site_size_msg_only SOURCES test_call_site_size_msg_only.c) add_code_size_test(test_call_site_size_fmt_args SOURCES test_call_site_size_fmt_args.c) +add_code_size_test(test_call_site_size_conditional_true SOURCES test_call_site_size_conditional.c DEFINES TEST_CONDITION=1) +add_code_size_test(test_call_site_size_conditional_false SOURCES test_call_site_size_conditional.c DEFINES TEST_CONDITION=0) +add_code_size_test(test_call_site_size_censoring_on SOURCES test_call_site_size_censoring.c DEFINES ZF_LOG_CENSORING=ZF_LOG_CENSORED) +add_code_size_test(test_call_site_size_censoring_off SOURCES test_call_site_size_censoring.c DEFINES ZF_LOG_CENSORING=ZF_LOG_UNCENSORED) diff --git a/tests/test_call_site_size_censoring.c b/tests/test_call_site_size_censoring.c new file mode 100644 index 0000000..fa3b768 --- /dev/null +++ b/tests/test_call_site_size_censoring.c @@ -0,0 +1,34 @@ +#define ZF_LOG_LEVEL ZF_LOG_INFO +#include +#include + +#define LOG_SOME_ONCE \ + ZF_LOG_SECRET(ZF_LOGI("Lorem ipsum dolor sit amet")); \ + time(0); \ + +static void log_some() +{ + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE +} + +int main(int argc, char *argv[]) +{ + (void)argc; (void)argv; + log_some(); + return 0; +} diff --git a/tests/test_call_site_size_conditional.c b/tests/test_call_site_size_conditional.c new file mode 100644 index 0000000..c9ca9c5 --- /dev/null +++ b/tests/test_call_site_size_conditional.c @@ -0,0 +1,40 @@ +#define ZF_LOG_LEVEL ZF_LOG_INFO +#include +#include + +#if TEST_CONDITION + #define CONDITION 1 < 2 +#else + #define CONDITION 1 > 2 +#endif + +#define LOG_SOME_ONCE \ + ZF_LOG_IF(CONDITION, ZF_LOGI("Lorem ipsum dolor sit amet")); \ + time(0); \ + +static void log_some() +{ + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE + LOG_SOME_ONCE +} + +int main(int argc, char *argv[]) +{ + (void)argc; (void)argv; + log_some(); + return 0; +} diff --git a/tests/zf_log.h.master b/tests/zf_log.h.master index 9917190..bdf9edb 100644 --- a/tests/zf_log.h.master +++ b/tests/zf_log.h.master @@ -7,12 +7,12 @@ * the current value of ZF_LOG_VERSION before including this file (or via * compiler command line): * - * #define ZF_LOG_VERSION_REQUIRED 3 + * #define ZF_LOG_VERSION_REQUIRED 4 * #include * * Compilation will fail when included file has different version. */ -#define ZF_LOG_VERSION 3 +#define ZF_LOG_VERSION 4 #if defined(ZF_LOG_VERSION_REQUIRED) #if ZF_LOG_VERSION_REQUIRED != ZF_LOG_VERSION #error different zf_log version required @@ -194,6 +194,115 @@ #define _ZF_LOG_TAG 0 #endif +/* Source location is part of a log line that describes location (function or + * method name, file name and line number, e.g. "runloop@main.cpp:68") of a + * log statement that produced it. + * Source location formats are: + * - ZF_LOG_SRCLOC_NONE - don't add source location to log line. + * - ZF_LOG_SRCLOC_SHORT - add source location in short form (file and line + * number, e.g. "@main.cpp:68"). + * - ZF_LOG_SRCLOC_LONG - add source location in long form (function or method + * name, file and line number, e.g. "runloop@main.cpp:68"). + */ +#define ZF_LOG_SRCLOC_NONE 0 +#define ZF_LOG_SRCLOC_SHORT 1 +#define ZF_LOG_SRCLOC_LONG 2 + +/* Source location format is configured per compilation module (.c/.cpp/.m + * file) by defining ZF_LOG_DEF_SRCLOC or ZF_LOG_SRCLOC. ZF_LOG_SRCLOC has + * higer priority and when defined overrides value provided by + * ZF_LOG_DEF_SRCLOC. + * + * Common practice is to define default format with ZF_LOG_DEF_SRCLOC in + * build script (e.g. Makefile, CMakeLists.txt, gyp, etc.) for the entire + * project or target: + * + * CC_ARGS := -DZF_LOG_DEF_SRCLOC=ZF_LOG_SRCLOC_LONG + * + * And when necessary to override it with ZF_LOG_SRCLOC in .c/.cpp/.m files + * before including zf_log.h: + * + * #define ZF_LOG_SRCLOC ZF_LOG_SRCLOC_NONE + * #include + * + * If both ZF_LOG_DEF_SRCLOC and ZF_LOG_SRCLOC are undefined, then + * ZF_LOG_SRCLOC_NONE will be used for release builds (NDEBUG is defined) and + * ZF_LOG_SRCLOC_LONG otherwise (NDEBUG is not defined). + */ +#if defined(ZF_LOG_SRCLOC) + #define _ZF_LOG_SRCLOC ZF_LOG_SRCLOC +#elif defined(ZF_LOG_DEF_SRCLOC) + #define _ZF_LOG_SRCLOC ZF_LOG_DEF_SRCLOC +#else + #ifdef NDEBUG + #define _ZF_LOG_SRCLOC ZF_LOG_SRCLOC_NONE + #else + #define _ZF_LOG_SRCLOC ZF_LOG_SRCLOC_LONG + #endif +#endif +#if ZF_LOG_SRCLOC_LONG == _ZF_LOG_SRCLOC + #define _ZF_LOG_FUNCTION __FUNCTION__ +#else + #define _ZF_LOG_FUNCTION 0 +#endif + +/* Censoring provides conditional logging of secret information, also known as + * Personally Identifiable Information (PII) or Sensitive Personal Information + * (SPI). Censoring can be either enabled (ZF_LOG_CENSORED) or disabled + * (ZF_LOG_UNCENSORED). When censoring is enabled, log statements marked as + * "secrets" will be ignored and will have zero overhead (arguments also will + * not be evaluated). + */ +#define ZF_LOG_CENSORED 1 +#define ZF_LOG_UNCENSORED 0 + +/* Censoring is configured per compilation module (.c/.cpp/.m file) by defining + * ZF_LOG_DEF_CENSORING or ZF_LOG_CENSORING. ZF_LOG_CENSORING has higer priority + * and when defined overrides value provided by ZF_LOG_DEF_CENSORING. + * + * Common practice is to define default censoring with ZF_LOG_DEF_CENSORING in + * build script (e.g. Makefile, CMakeLists.txt, gyp, etc.) for the entire + * project or target: + * + * CC_ARGS := -DZF_LOG_DEF_CENSORING=ZF_LOG_CENSORED + * + * And when necessary to override it with ZF_LOG_CENSORING in .c/.cpp/.m files + * before including zf_log.h (consider doing it only for debug purposes and be + * very careful not to push such temporary changes to source control): + * + * #define ZF_LOG_CENSORING ZF_LOG_UNCENSORED + * #include + * + * If both ZF_LOG_DEF_CENSORING and ZF_LOG_CENSORING are undefined, then + * ZF_LOG_CENSORED will be used for release builds (NDEBUG is defined) and + * ZF_LOG_UNCENSORED otherwise (NDEBUG is not defined). + */ +#if defined(ZF_LOG_CENSORING) + #define _ZF_LOG_CENSORING ZF_LOG_CENSORING +#elif defined(ZF_LOG_DEF_CENSORING) + #define _ZF_LOG_CENSORING ZF_LOG_DEF_CENSORING +#else + #ifdef NDEBUG + #define _ZF_LOG_CENSORING ZF_LOG_CENSORED + #else + #define _ZF_LOG_CENSORING ZF_LOG_UNCENSORED + #endif +#endif + +/* Check censoring at compile time. Evaluates to true when censoring is disabled + * (i.e. when secrets will be logged). For example: + * + * #if ZF_LOG_SECRETS + * char ssn[16]; + * getSocialSecurityNumber(ssn); + * ZF_LOGI("Customer ssn: %s", ssn); + * #endif + * + * See ZF_LOG_SECRET() macro for a more convenient way of guarding single log + * statement. + */ +#define ZF_LOG_SECRETS (ZF_LOG_UNCENSORED == _ZF_LOG_CENSORING) + /* Static (compile-time) initialization support allows to configure logging * before entering main() function. This mostly useful in C++ where functions * and methods could be called during initialization of global objects. Those @@ -260,7 +369,35 @@ * possible conflicts with other libraries / components that also could use * zf_log for logging). Value must be without quotes, for example: * - * CC_ARGS := -DZF_LOG_LIBRARY_PREFIX=my_lib + * CC_ARGS := -DZF_LOG_LIBRARY_PREFIX=my_lib_ + * + * Note, that in this mode ZF_LOG_LIBRARY_PREFIX must be defined when building + * zf_log library AND it also must be defined to the same value when building + * a library that uses it. For example, consider fictional KittyHttp library + * that wants to use zf_log for logging. First approach that could be taken is + * to add zf_log.h and zf_log.c to the KittyHttp's source code tree directly. + * In that case it will be enough just to define ZF_LOG_LIBRARY_PREFIX in + * KittyHttp's build script: + * + * // KittyHttp/CMakeLists.txt + * target_compile_definitions(KittyHttp PRIVATE + * "ZF_LOG_LIBRARY_PREFIX=KittyHttp_") + * + * If KittyHttp doesn't want to include zf_log source code in its source tree + * and wants to build zf_log as a separate library than zf_log library must be + * built with ZF_LOG_LIBRARY_PREFIX defined to KittyHttp_ AND KittyHttp library + * itself also needs to define ZF_LOG_LIBRARY_PREFIX to KittyHttp_. It can do + * so either in its build script, as in example above, or by providing a + * wrapper header that KittyHttp library will need to use instead of zf_log.h: + * + * // KittyHttpLogging.h + * #define ZF_LOG_LIBRARY_PREFIX KittyHttp_ + * #include + * + * Regardless of the method chosen, the end result is that zf_log symbols will + * be prefixed with "KittyHttp_", so if a user of KittyHttp (say DogeBrowser) + * also uses zf_log for logging, they will not interferer with each other. Both + * will have their own log level, output facility, format options etc. */ #ifdef ZF_LOG_LIBRARY_PREFIX #define _ZF_LOG_DECOR__(prefix, name) prefix ## name @@ -296,21 +433,23 @@ #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) #define _ZF_LOG_INLINE __inline - #define _ZF_LOG_ONCE \ + #define _ZF_LOG_IF(cond) \ __pragma(warning(push)) \ __pragma(warning(disable:4127)) \ - while(0) \ + if(cond) \ __pragma(warning(pop)) - #define _ZF_LOG_NEVER \ + #define _ZF_LOG_WHILE(cond) \ __pragma(warning(push)) \ __pragma(warning(disable:4127)) \ - if(0) \ + while(cond) \ __pragma(warning(pop)) #else #define _ZF_LOG_INLINE inline - #define _ZF_LOG_ONCE while(0) - #define _ZF_LOG_NEVER if(0) + #define _ZF_LOG_IF(cond) if(cond) + #define _ZF_LOG_WHILE(cond) while(cond) #endif +#define _ZF_LOG_NEVER _ZF_LOG_IF(0) +#define _ZF_LOG_ONCE _ZF_LOG_WHILE(0) #ifdef __cplusplus extern "C" { @@ -390,8 +529,8 @@ zf_log_format; typedef struct zf_log_output { unsigned mask; /* What to put into log line buffer (see ZF_LOG_PUT_XXX) */ - zf_log_output_cb callback; /* Output callback function */ void *arg; /* User provided output callback argument */ + zf_log_output_cb callback; /* Output callback function */ } zf_log_output; @@ -400,11 +539,11 @@ zf_log_output; * Mask allows to control what information will be added to the log line buffer * before callback function is invoked. Default mask value is ZF_LOG_PUT_STD. */ -void zf_log_set_output_v(const unsigned mask, const zf_log_output_cb callback, - void *const arg); +void zf_log_set_output_v(const unsigned mask, void *const arg, + const zf_log_output_cb callback); static _ZF_LOG_INLINE void zf_log_set_output_p(const zf_log_output *const output) { - zf_log_set_output_v(output->mask, output->callback, output->arg); + zf_log_set_output_v(output->mask, output->arg, output->callback); } /* Used with _AUX macros and allows to override global format and output @@ -412,7 +551,7 @@ static _ZF_LOG_INLINE void zf_log_set_output_p(const zf_log_output *const output * global configuration. Example: * * static const zf_log_output module_output = { - * ZF_LOG_PUT_STD, custom_output_callback, 0 + * ZF_LOG_PUT_STD, 0, custom_output_callback * }; * static const zf_log_spec module_spec = { * ZF_LOG_GLOBAL_FORMAT, &module_output @@ -432,6 +571,27 @@ zf_log_spec; } #endif +/* Execute log statement if condition is true. Example: + * + * ZF_LOG_IF(1 < 2, ZF_LOGI("Log this")); + * ZF_LOG_IF(1 > 2, ZF_LOGI("Don't log this")); + * + * Keep in mind though, that if condition can't be evaluated at compile time, + * then it will be evaluated at run time. This will increase exectuable size + * and can have noticeable performance overhead. Try to limit conditions to + * expressions that can be evaluated at compile time. + */ +#define ZF_LOG_IF(cond, f) do { _ZF_LOG_IF((cond)) { f; } } _ZF_LOG_ONCE + +/* Mark log statement as "secret". Log statements that are marked as secrets + * will NOT be executed when censoring is enabled (see ZF_LOG_CENSORED). + * Example: + * + * ZF_LOG_SECRET(ZF_LOGI("Credit card: %s", credit_card)); + * ZF_LOG_SECRET(ZF_LOGD_MEM(cipher, cipher_sz, "Cipher bytes:")); + */ +#define ZF_LOG_SECRET(f) ZF_LOG_IF(ZF_LOG_SECRETS, f) + /* Check "current" log level at compile time (ignoring "output" log level). * Evaluates to true when specified log level is enabled. For example: * @@ -564,57 +724,64 @@ void _zf_log_write_mem_aux( * - ZF_LOGE_STR("preformatted string"); * - ZF_LOGF_STR("preformatted string"); * + * Explicit log level and tag macros: + * - ZF_LOG_WRITE(level, tag, "format string", args, ...) + * - ZF_LOG_WRITE_MEM(level, tag, data_ptr, data_sz, "format string", args, ...) + * - ZF_LOG_WRITE_AUX(&log_instance, level, tag, "format string", args, ...) + * - ZF_LOG_WRITE_MEM_AUX(&log_instance, level, tag, data_ptr, data_sz, + * "format string", args, ...) + * * Format string follows printf() conventions. Both data_ptr and data_sz could - * be 0. Most compilers will verify that type of arguments match format - * specifiers in format string. + * be 0. Tag can be 0 as well. Most compilers will verify that type of arguments + * match format specifiers in format string. * * Library assuming UTF-8 encoding for all strings (char *), including format * string itself. */ -#ifdef NDEBUG - #define _ZF_LOG_IMP(lvl, tag, ...) \ +#if ZF_LOG_SRCLOC_NONE == _ZF_LOG_SRCLOC + #define ZF_LOG_WRITE(lvl, tag, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ _zf_log_write(lvl, tag, __VA_ARGS__); \ } _ZF_LOG_ONCE - #define _ZF_LOG_MEM_IMP(lvl, tag, d, d_sz, ...) \ + #define ZF_LOG_WRITE_MEM(lvl, tag, d, d_sz, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ _zf_log_write_mem(lvl, tag, d, d_sz, __VA_ARGS__); \ } _ZF_LOG_ONCE - #define _ZF_LOG_AUX_IMP(log, lvl, tag, ...) \ + #define ZF_LOG_WRITE_AUX(log, lvl, tag, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ _zf_log_write_aux(log, lvl, tag, __VA_ARGS__); \ } _ZF_LOG_ONCE - #define _ZF_LOG_MEM_AUX_IMP(log, lvl, tag, d, d_sz, ...) \ + #define ZF_LOG_WRITE_MEM_AUX(log, lvl, tag, d, d_sz, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ _zf_log_write_mem_aux(log, lvl, tag, d, d_sz, __VA_ARGS__); \ } _ZF_LOG_ONCE #else - #define _ZF_LOG_IMP(lvl, tag, ...) \ + #define ZF_LOG_WRITE(lvl, tag, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ - _zf_log_write_d(__FUNCTION__, __FILE__, __LINE__, \ + _zf_log_write_d(_ZF_LOG_FUNCTION, __FILE__, __LINE__, \ lvl, tag, __VA_ARGS__); \ } _ZF_LOG_ONCE - #define _ZF_LOG_MEM_IMP(lvl, tag, d, d_sz, ...) \ + #define ZF_LOG_WRITE_MEM(lvl, tag, d, d_sz, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ - _zf_log_write_mem_d(__FUNCTION__, __FILE__, __LINE__, \ + _zf_log_write_mem_d(_ZF_LOG_FUNCTION, __FILE__, __LINE__, \ lvl, tag, d, d_sz, __VA_ARGS__); \ } _ZF_LOG_ONCE - #define _ZF_LOG_AUX_IMP(log, lvl, tag, ...) \ + #define ZF_LOG_WRITE_AUX(log, lvl, tag, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ - _zf_log_write_aux_d(__FUNCTION__, __FILE__, __LINE__, \ + _zf_log_write_aux_d(_ZF_LOG_FUNCTION, __FILE__, __LINE__, \ log, lvl, tag, __VA_ARGS__); \ } _ZF_LOG_ONCE - #define _ZF_LOG_MEM_AUX_IMP(log, lvl, tag, d, d_sz, ...) \ + #define ZF_LOG_WRITE_MEM_AUX(log, lvl, tag, d, d_sz, ...) \ do { \ if (ZF_LOG_ON(lvl)) \ - _zf_log_write_mem_aux_d(__FUNCTION__, __FILE__, __LINE__, \ + _zf_log_write_mem_aux_d(_ZF_LOG_FUNCTION, __FILE__, __LINE__, \ log, lvl, tag, d, d_sz, __VA_ARGS__); \ } _ZF_LOG_ONCE #endif @@ -626,13 +793,13 @@ static _ZF_LOG_INLINE void _zf_log_unused(const int dummy, ...) {(void)dummy;} #if ZF_LOG_ENABLED_VERBOSE #define ZF_LOGV(...) \ - _ZF_LOG_IMP(ZF_LOG_VERBOSE, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE(ZF_LOG_VERBOSE, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGV_AUX(log, ...) \ - _ZF_LOG_AUX_IMP(log, ZF_LOG_VERBOSE, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE_AUX(log, ZF_LOG_VERBOSE, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGV_MEM(d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(ZF_LOG_VERBOSE, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(ZF_LOG_VERBOSE, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #define ZF_LOGV_MEM_AUX(log, d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(log, ZF_LOG_VERBOSE, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(log, ZF_LOG_VERBOSE, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define ZF_LOGV(...) _ZF_LOG_UNUSED(__VA_ARGS__) #define ZF_LOGV_AUX(...) _ZF_LOG_UNUSED(__VA_ARGS__) @@ -642,13 +809,13 @@ static _ZF_LOG_INLINE void _zf_log_unused(const int dummy, ...) {(void)dummy;} #if ZF_LOG_ENABLED_DEBUG #define ZF_LOGD(...) \ - _ZF_LOG_IMP(ZF_LOG_DEBUG, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE(ZF_LOG_DEBUG, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGD_AUX(log, ...) \ - _ZF_LOG_AUX_IMP(log, ZF_LOG_DEBUG, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE_AUX(log, ZF_LOG_DEBUG, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGD_MEM(d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(ZF_LOG_DEBUG, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(ZF_LOG_DEBUG, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #define ZF_LOGD_MEM_AUX(log, d, d_sz, ...) \ - _ZF_LOG_MEM_AUX_IMP(log, ZF_LOG_DEBUG, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM_AUX(log, ZF_LOG_DEBUG, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define ZF_LOGD(...) _ZF_LOG_UNUSED(__VA_ARGS__) #define ZF_LOGD_AUX(...) _ZF_LOG_UNUSED(__VA_ARGS__) @@ -658,13 +825,13 @@ static _ZF_LOG_INLINE void _zf_log_unused(const int dummy, ...) {(void)dummy;} #if ZF_LOG_ENABLED_INFO #define ZF_LOGI(...) \ - _ZF_LOG_IMP(ZF_LOG_INFO, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE(ZF_LOG_INFO, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGI_AUX(log, ...) \ - _ZF_LOG_AUX_IMP(log, ZF_LOG_INFO, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE_AUX(log, ZF_LOG_INFO, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGI_MEM(d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(ZF_LOG_INFO, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(ZF_LOG_INFO, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #define ZF_LOGI_MEM_AUX(log, d, d_sz, ...) \ - _ZF_LOG_MEM_AUX_IMP(log, ZF_LOG_INFO, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM_AUX(log, ZF_LOG_INFO, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define ZF_LOGI(...) _ZF_LOG_UNUSED(__VA_ARGS__) #define ZF_LOGI_AUX(...) _ZF_LOG_UNUSED(__VA_ARGS__) @@ -674,13 +841,13 @@ static _ZF_LOG_INLINE void _zf_log_unused(const int dummy, ...) {(void)dummy;} #if ZF_LOG_ENABLED_WARN #define ZF_LOGW(...) \ - _ZF_LOG_IMP(ZF_LOG_WARN, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE(ZF_LOG_WARN, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGW_AUX(log, ...) \ - _ZF_LOG_AUX_IMP(log, ZF_LOG_WARN, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE_AUX(log, ZF_LOG_WARN, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGW_MEM(d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(ZF_LOG_WARN, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(ZF_LOG_WARN, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #define ZF_LOGW_MEM_AUX(log, d, d_sz, ...) \ - _ZF_LOG_MEM_AUX_IMP(log, ZF_LOG_WARN, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM_AUX(log, ZF_LOG_WARN, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define ZF_LOGW(...) _ZF_LOG_UNUSED(__VA_ARGS__) #define ZF_LOGW_AUX(...) _ZF_LOG_UNUSED(__VA_ARGS__) @@ -690,13 +857,13 @@ static _ZF_LOG_INLINE void _zf_log_unused(const int dummy, ...) {(void)dummy;} #if ZF_LOG_ENABLED_ERROR #define ZF_LOGE(...) \ - _ZF_LOG_IMP(ZF_LOG_ERROR, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE(ZF_LOG_ERROR, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGE_AUX(log, ...) \ - _ZF_LOG_AUX_IMP(log, ZF_LOG_ERROR, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE_AUX(log, ZF_LOG_ERROR, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGE_MEM(d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(ZF_LOG_ERROR, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(ZF_LOG_ERROR, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #define ZF_LOGE_MEM_AUX(log, d, d_sz, ...) \ - _ZF_LOG_MEM_AUX_IMP(log, ZF_LOG_ERROR, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM_AUX(log, ZF_LOG_ERROR, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define ZF_LOGE(...) _ZF_LOG_UNUSED(__VA_ARGS__) #define ZF_LOGE_AUX(...) _ZF_LOG_UNUSED(__VA_ARGS__) @@ -706,13 +873,13 @@ static _ZF_LOG_INLINE void _zf_log_unused(const int dummy, ...) {(void)dummy;} #if ZF_LOG_ENABLED_FATAL #define ZF_LOGF(...) \ - _ZF_LOG_IMP(ZF_LOG_FATAL, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE(ZF_LOG_FATAL, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGF_AUX(log, ...) \ - _ZF_LOG_AUX_IMP(log, ZF_LOG_FATAL, _ZF_LOG_TAG, __VA_ARGS__) + ZF_LOG_WRITE_AUX(log, ZF_LOG_FATAL, _ZF_LOG_TAG, __VA_ARGS__) #define ZF_LOGF_MEM(d, d_sz, ...) \ - _ZF_LOG_MEM_IMP(ZF_LOG_FATAL, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM(ZF_LOG_FATAL, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #define ZF_LOGF_MEM_AUX(log, d, d_sz, ...) \ - _ZF_LOG_MEM_AUX_IMP(log, ZF_LOG_FATAL, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) + ZF_LOG_WRITE_MEM_AUX(log, ZF_LOG_FATAL, _ZF_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define ZF_LOGF(...) _ZF_LOG_UNUSED(__VA_ARGS__) #define ZF_LOGF_AUX(...) _ZF_LOG_UNUSED(__VA_ARGS__) @@ -745,7 +912,7 @@ extern "C" { */ enum { ZF_LOG_OUT_STDERR_MASK = ZF_LOG_PUT_STD }; void zf_log_out_stderr_callback(const zf_log_message *const msg, void *arg); -#define ZF_LOG_OUT_STDERR ZF_LOG_OUT_STDERR_MASK, zf_log_out_stderr_callback, 0 +#define ZF_LOG_OUT_STDERR ZF_LOG_OUT_STDERR_MASK, 0, zf_log_out_stderr_callback /* Predefined spec for stderr. Uses global format options (ZF_LOG_GLOBAL_FORMAT) * and ZF_LOG_OUT_STDERR. Could be used to force output to stderr for a