X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flogging%2Flog.h;h=20754c1f1d422b5c3ac67043f9ede4a7e3c23a75;hb=4fa90f321f51af8f5bfc48eee1435e2f41d853b3;hp=c9aa4bad3242c783987c295426bdaa99a5f84813;hpb=ba32ead5eaae0ebca1f4f81a2da7e25b814af747;p=babeltrace.git diff --git a/src/logging/log.h b/src/logging/log.h index c9aa4bad..20754c1f 100644 --- a/src/logging/log.h +++ b/src/logging/log.h @@ -13,7 +13,8 @@ #include #include #include -#include +#include + #include "common/macros.h" #include "common/assert.h" @@ -40,7 +41,7 @@ * - BT_LOG_ERROR - happened something possible, but highly unexpected. The * process is able to recover and continue execution. * Example: out of memory (could also be FATAL if not handled properly). - * - BT_LOG_WARN - happened something that *usually* should not happen and + * - BT_LOG_WARNING - happened something that *usually* should not happen and * significantly changes application behavior for some period of time. * Example: configuration file not found, auth error. * - BT_LOG_INFO - happened significant life cycle event or major state @@ -48,27 +49,28 @@ * Example: app started, user logged in. * - BT_LOG_DEBUG - minimal set of events that could help to reconstruct the * execution path. Usually disabled in release builds. - * - BT_LOG_VERBOSE - all other events. Usually disabled in release builds. + * - BT_LOG_TRACE - all other events. Usually disabled in release builds. * * *Ideally*, log file of debugged, well tested, production ready application * should be empty or very small. Choosing a right log level is as important as * providing short and self descriptive log message. */ -#define BT_LOG_VERBOSE BT_LOGGING_LEVEL_VERBOSE +#define BT_LOG_TRACE BT_LOGGING_LEVEL_TRACE #define BT_LOG_DEBUG BT_LOGGING_LEVEL_DEBUG #define BT_LOG_INFO BT_LOGGING_LEVEL_INFO -#define BT_LOG_WARN BT_LOGGING_LEVEL_WARN +#define BT_LOG_WARNING BT_LOGGING_LEVEL_WARNING #define BT_LOG_ERROR BT_LOGGING_LEVEL_ERROR #define BT_LOG_FATAL BT_LOGGING_LEVEL_FATAL #define BT_LOG_NONE BT_LOGGING_LEVEL_NONE /* "Current" log level is a compile time check and has no runtime overhead. Log - * level that is below current log level it said to be "disabled". Otherwise, - * it's "enabled". Log messages that are disabled has no runtime overhead - they - * are converted to no-op by preprocessor and then eliminated by compiler. - * Current log level is configured per compilation module (.c/.cpp/.m file) by - * defining BT_LOG_DEF_LEVEL or BT_LOG_LEVEL. BT_LOG_LEVEL has higer priority - * and when defined overrides value provided by BT_LOG_DEF_LEVEL. + * level that is below current log level it said to be "disabled". + * Otherwise, it's "enabled". Log messages that are disabled has no + * runtime overhead - they are converted to no-op by preprocessor and + * then eliminated by compiler. Current log level is configured per + * compilation module (.c/.cpp/.m file) by defining BT_LOG_DEF_LEVEL or + * BT_MINIMAL_LOG_LEVEL. BT_MINIMAL_LOG_LEVEL has higer priority and + * when defined overrides value provided by BT_LOG_DEF_LEVEL. * * Common practice is to define default current log level with BT_LOG_DEF_LEVEL * in build script (e.g. Makefile, CMakeLists.txt, gyp, etc.) for the entire @@ -76,37 +78,38 @@ * * CC_ARGS := -DBT_LOG_DEF_LEVEL=BT_LOG_INFO * - * And when necessary to override it with BT_LOG_LEVEL in .c/.cpp/.m files + * And when necessary to override it with BT_MINIMAL_LOG_LEVEL in .c/.cpp/.m files * before including bt_log.h: * - * #define BT_LOG_LEVEL BT_LOG_VERBOSE + * #define BT_MINIMAL_LOG_LEVEL BT_LOG_TRACE * #include "logging.h" * - * If both BT_LOG_DEF_LEVEL and BT_LOG_LEVEL are undefined, then + * If both BT_LOG_DEF_LEVEL and BT_MINIMAL_LOG_LEVEL are undefined, then * BT_LOG_INFO will be used for release builds (BT_DEBUG_MODE is NOT * defined) and BT_LOG_DEBUG otherwise (BT_DEBUG_MODE is defined). */ -#if defined(BT_LOG_LEVEL) - #define _BT_LOG_LEVEL BT_LOG_LEVEL +#if defined(BT_MINIMAL_LOG_LEVEL) + #define _BT_MINIMAL_LOG_LEVEL BT_MINIMAL_LOG_LEVEL #elif defined(BT_LOG_DEF_LEVEL) - #define _BT_LOG_LEVEL BT_LOG_DEF_LEVEL + #define _BT_MINIMAL_LOG_LEVEL BT_LOG_DEF_LEVEL #else #ifdef BT_DEBUG_MODE - #define _BT_LOG_LEVEL BT_LOG_DEBUG + #define _BT_MINIMAL_LOG_LEVEL BT_LOG_DEBUG #else - #define _BT_LOG_LEVEL BT_LOG_INFO + #define _BT_MINIMAL_LOG_LEVEL BT_LOG_INFO #endif #endif /* "Output" log level is a runtime check. When log level is below output log - * level it said to be "turned off" (or just "off" for short). Otherwise it's - * "turned on" (or just "on"). Log levels that were "disabled" (see - * BT_LOG_LEVEL and BT_LOG_DEF_LEVEL) can't be "turned on", but "enabled" log - * levels could be "turned off". Only messages with log level which is - * "turned on" will reach output facility. All other messages will be ignored - * (and their arguments will not be evaluated). Output log level is a global - * property and configured per process using bt_log_set_output_level() function - * which can be called at any time. + * level it said to be "turned off" (or just "off" for short). Otherwise + * it's "turned on" (or just "on"). Log levels that were "disabled" (see + * BT_MINIMAL_LOG_LEVEL and BT_LOG_DEF_LEVEL) can't be "turned on", but + * "enabled" log levels could be "turned off". Only messages with log + * level which is "turned on" will reach output facility. All other + * messages will be ignored (and their arguments will not be evaluated). + * Output log level is a global property and configured per process + * using bt_log_set_output_level() function which can be called at any + * time. * * Though in some cases it could be useful to configure output log level per * compilation module or per library. There are two ways to achieve that: @@ -116,11 +119,13 @@ * BT_LOG_LIBRARY_PREFIX defined to library specific prefix. See * BT_LOG_LIBRARY_PREFIX for more details. * - * When defined, BT_LOG_OUTPUT_LEVEL must evaluate to integral value that - * corresponds to desired output log level. Use it only when compilation module - * is required to have output log level which is different from global output - * log level set by bt_log_set_output_level() function. For other cases, - * consider defining BT_LOG_LEVEL or using bt_log_set_output_level() function. + * When defined, BT_LOG_OUTPUT_LEVEL must evaluate to integral value + * that corresponds to desired output log level. Use it only when + * compilation module is required to have output log level which is + * different from global output log level set by + * bt_log_set_output_level() function. For other cases, consider + * defining BT_MINIMAL_LOG_LEVEL or using bt_log_set_output_level() + * function. * * Example: * @@ -134,13 +139,14 @@ * g_module_log_level = on? BT_LOG_DEBUG: BT_LOG_INFO; * } * - * Note on performance. This expression will be evaluated each time message is - * logged (except when message log level is "disabled" - see BT_LOG_LEVEL for - * details). Keep this expression as simple as possible, otherwise it will not - * only add runtime overhead, but also will increase size of call site (which - * will result in larger executable). The prefered way is to use integer - * variable (as in example above). If structure must be used, log_level field - * must be the first field in this structure: + * Note on performance. This expression will be evaluated each time + * message is logged (except when message log level is "disabled" - see + * BT_MINIMAL_LOG_LEVEL for details). Keep this expression as simple as + * possible, otherwise it will not only add runtime overhead, but also + * will increase size of call site (which will result in larger + * executable). The prefered way is to use integer variable (as in + * example above). If structure must be used, log_level field must be + * the first field in this structure: * * #define BT_LOG_OUTPUT_LEVEL (g_config.log_level) * #include "logging.h" @@ -506,7 +512,7 @@ void bt_log_set_tag_prefix(const char *const prefix); */ void bt_log_set_mem_width(const unsigned w); -/* Set "output" log level. See BT_LOG_LEVEL and BT_LOG_OUTPUT_LEVEL for more +/* Set "output" log level. See BT_MINIMAL_LOG_LEVEL and BT_LOG_OUTPUT_LEVEL for more * info about log levels. */ void bt_log_set_output_level(const int lvl); @@ -637,13 +643,13 @@ bt_log_spec; * BT_LOGD("enum value: %s", g_enum_strings[v]); * #endif * - * See BT_LOG_LEVEL for details. + * See BT_MINIMAL_LOG_LEVEL for details. */ -#define BT_LOG_ENABLED(lvl) ((lvl) >= _BT_LOG_LEVEL) -#define BT_LOG_ENABLED_VERBOSE BT_LOG_ENABLED(BT_LOG_VERBOSE) +#define BT_LOG_ENABLED(lvl) ((lvl) >= _BT_MINIMAL_LOG_LEVEL) +#define BT_LOG_ENABLED_TRACE BT_LOG_ENABLED(BT_LOG_TRACE) #define BT_LOG_ENABLED_DEBUG BT_LOG_ENABLED(BT_LOG_DEBUG) #define BT_LOG_ENABLED_INFO BT_LOG_ENABLED(BT_LOG_INFO) -#define BT_LOG_ENABLED_WARN BT_LOG_ENABLED(BT_LOG_WARN) +#define BT_LOG_ENABLED_WARNING BT_LOG_ENABLED(BT_LOG_WARNING) #define BT_LOG_ENABLED_ERROR BT_LOG_ENABLED(BT_LOG_ERROR) #define BT_LOG_ENABLED_FATAL BT_LOG_ENABLED(BT_LOG_FATAL) @@ -664,10 +670,10 @@ bt_log_spec; (BT_LOG_ENABLED((lvl)) && (lvl) >= (cur_lvl)) #define BT_LOG_ON(lvl) \ (BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL) -#define BT_LOG_ON_VERBOSE BT_LOG_ON(BT_LOG_VERBOSE) +#define BT_LOG_ON_TRACE BT_LOG_ON(BT_LOG_TRACE) #define BT_LOG_ON_DEBUG BT_LOG_ON(BT_LOG_DEBUG) #define BT_LOG_ON_INFO BT_LOG_ON(BT_LOG_INFO) -#define BT_LOG_ON_WARN BT_LOG_ON(BT_LOG_WARN) +#define BT_LOG_ON_WARNING BT_LOG_ON(BT_LOG_WARNING) #define BT_LOG_ON_ERROR BT_LOG_ON(BT_LOG_ERROR) #define BT_LOG_ON_FATAL BT_LOG_ON(BT_LOG_FATAL) @@ -734,7 +740,7 @@ void _bt_log_write_mem_aux( #endif /* Message logging macros: - * - BT_LOGV("format string", args, ...) + * - BT_LOGT("format string", args, ...) * - BT_LOGD("format string", args, ...) * - BT_LOGI("format string", args, ...) * - BT_LOGW("format string", args, ...) @@ -742,7 +748,7 @@ void _bt_log_write_mem_aux( * - BT_LOGF("format string", args, ...) * * Message and error string (errno) logging macros: - * - BT_LOGV_ERRNO("initial message", "format string", args, ...) + * - BT_LOGT_ERRNO("initial message", "format string", args, ...) * - BT_LOGD_ERRNO("initial message", "format string", args, ...) * - BT_LOGI_ERRNO("initial message", "format string", args, ...) * - BT_LOGW_ERRNO("initial message", "format string", args, ...) @@ -750,7 +756,7 @@ void _bt_log_write_mem_aux( * - BT_LOGF_ERRNO("initial message", "format string", args, ...) * * Memory logging macros: - * - BT_LOGV_MEM(data_ptr, data_sz, "format string", args, ...) + * - BT_LOGT_MEM(data_ptr, data_sz, "format string", args, ...) * - BT_LOGD_MEM(data_ptr, data_sz, "format string", args, ...) * - BT_LOGI_MEM(data_ptr, data_sz, "format string", args, ...) * - BT_LOGW_MEM(data_ptr, data_sz, "format string", args, ...) @@ -758,7 +764,7 @@ void _bt_log_write_mem_aux( * - BT_LOGF_MEM(data_ptr, data_sz, "format string", args, ...) * * Auxiliary logging macros: - * - BT_LOGV_AUX(&log_instance, "format string", args, ...) + * - BT_LOGT_AUX(&log_instance, "format string", args, ...) * - BT_LOGD_AUX(&log_instance, "format string", args, ...) * - BT_LOGI_AUX(&log_instance, "format string", args, ...) * - BT_LOGW_AUX(&log_instance, "format string", args, ...) @@ -766,7 +772,7 @@ void _bt_log_write_mem_aux( * - BT_LOGF_AUX(&log_instance, "format string", args, ...) * * Auxiliary memory logging macros: - * - BT_LOGV_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...) + * - BT_LOGT_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...) * - BT_LOGD_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...) * - BT_LOGI_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...) * - BT_LOGW_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...) @@ -774,7 +780,7 @@ void _bt_log_write_mem_aux( * - BT_LOGF_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...) * * Preformatted string logging macros: - * - BT_LOGV_STR("preformatted string"); + * - BT_LOGT_STR("preformatted string"); * - BT_LOGD_STR("preformatted string"); * - BT_LOGI_STR("preformatted string"); * - BT_LOGW_STR("preformatted string"); @@ -874,22 +880,22 @@ static _BT_LOG_INLINE void _bt_log_unused(const int dummy, ...) {(void)dummy;} #define _BT_LOG_UNUSED(...) \ do { _BT_LOG_NEVER _bt_log_unused(0, __VA_ARGS__); } _BT_LOG_ONCE -#if BT_LOG_ENABLED_VERBOSE - #define BT_LOGV(...) \ - BT_LOG_WRITE(BT_LOG_VERBOSE, _BT_LOG_TAG, __VA_ARGS__) - #define BT_LOGV_ERRNO(...) \ - BT_LOG_WRITE_ERRNO(BT_LOG_VERBOSE, _BT_LOG_TAG, __VA_ARGS__) - #define BT_LOGV_AUX(log, ...) \ - BT_LOG_WRITE_AUX(log, BT_LOG_VERBOSE, _BT_LOG_TAG, __VA_ARGS__) - #define BT_LOGV_MEM(d, d_sz, ...) \ - BT_LOG_WRITE_MEM(BT_LOG_VERBOSE, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) - #define BT_LOGV_MEM_AUX(log, d, d_sz, ...) \ - BT_LOG_WRITE_MEM(log, BT_LOG_VERBOSE, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) +#if BT_LOG_ENABLED_TRACE + #define BT_LOGT(...) \ + BT_LOG_WRITE(BT_LOG_TRACE, _BT_LOG_TAG, __VA_ARGS__) + #define BT_LOGT_ERRNO(...) \ + BT_LOG_WRITE_ERRNO(BT_LOG_TRACE, _BT_LOG_TAG, __VA_ARGS__) + #define BT_LOGT_AUX(log, ...) \ + BT_LOG_WRITE_AUX(log, BT_LOG_TRACE, _BT_LOG_TAG, __VA_ARGS__) + #define BT_LOGT_MEM(d, d_sz, ...) \ + BT_LOG_WRITE_MEM(BT_LOG_TRACE, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) + #define BT_LOGT_MEM_AUX(log, d, d_sz, ...) \ + BT_LOG_WRITE_MEM(log, BT_LOG_TRACE, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) #else - #define BT_LOGV(...) _BT_LOG_UNUSED(__VA_ARGS__) - #define BT_LOGV_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) - #define BT_LOGV_MEM(...) _BT_LOG_UNUSED(__VA_ARGS__) - #define BT_LOGV_MEM_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) + #define BT_LOGT(...) _BT_LOG_UNUSED(__VA_ARGS__) + #define BT_LOGT_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) + #define BT_LOGT_MEM(...) _BT_LOG_UNUSED(__VA_ARGS__) + #define BT_LOGT_MEM_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) #endif #if BT_LOG_ENABLED_DEBUG @@ -928,17 +934,17 @@ static _BT_LOG_INLINE void _bt_log_unused(const int dummy, ...) {(void)dummy;} #define BT_LOGI_MEM_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) #endif -#if BT_LOG_ENABLED_WARN +#if BT_LOG_ENABLED_WARNING #define BT_LOGW(...) \ - BT_LOG_WRITE(BT_LOG_WARN, _BT_LOG_TAG, __VA_ARGS__) + BT_LOG_WRITE(BT_LOG_WARNING, _BT_LOG_TAG, __VA_ARGS__) #define BT_LOGW_ERRNO(...) \ - BT_LOG_WRITE_ERRNO(BT_LOG_WARN, _BT_LOG_TAG, __VA_ARGS__) + BT_LOG_WRITE_ERRNO(BT_LOG_WARNING, _BT_LOG_TAG, __VA_ARGS__) #define BT_LOGW_AUX(log, ...) \ - BT_LOG_WRITE_AUX(log, BT_LOG_WARN, _BT_LOG_TAG, __VA_ARGS__) + BT_LOG_WRITE_AUX(log, BT_LOG_WARNING, _BT_LOG_TAG, __VA_ARGS__) #define BT_LOGW_MEM(d, d_sz, ...) \ - BT_LOG_WRITE_MEM(BT_LOG_WARN, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) + BT_LOG_WRITE_MEM(BT_LOG_WARNING, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) #define BT_LOGW_MEM_AUX(log, d, d_sz, ...) \ - BT_LOG_WRITE_MEM_AUX(log, BT_LOG_WARN, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) + BT_LOG_WRITE_MEM_AUX(log, BT_LOG_WARNING, _BT_LOG_TAG, d, d_sz, __VA_ARGS__) #else #define BT_LOGW(...) _BT_LOG_UNUSED(__VA_ARGS__) #define BT_LOGW_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) @@ -982,7 +988,7 @@ static _BT_LOG_INLINE void _bt_log_unused(const int dummy, ...) {(void)dummy;} #define BT_LOGF_MEM_AUX(...) _BT_LOG_UNUSED(__VA_ARGS__) #endif -#define BT_LOGV_STR(s) BT_LOGV("%s", (s)) +#define BT_LOGT_STR(s) BT_LOGT("%s", (s)) #define BT_LOGD_STR(s) BT_LOGD("%s", (s)) #define BT_LOGI_STR(s) BT_LOGI("%s", (s)) #define BT_LOGW_STR(s) BT_LOGW("%s", (s)) @@ -1032,8 +1038,8 @@ char bt_log_get_letter_from_level(int level) char letter; switch (level) { - case BT_LOG_VERBOSE: - letter = 'V'; + case BT_LOG_TRACE: + letter = 'T'; break; case BT_LOG_DEBUG: letter = 'D'; @@ -1041,7 +1047,7 @@ char bt_log_get_letter_from_level(int level) case BT_LOG_INFO: letter = 'I'; break; - case BT_LOG_WARN: + case BT_LOG_WARNING: letter = 'W'; break; case BT_LOG_ERROR: @@ -1071,9 +1077,9 @@ int bt_log_get_level_from_string(const char *str) BT_ASSERT(str); - if (strcmp(str, "VERBOSE") == 0 || - strcmp(str, "V") == 0) { - level = BT_LOG_VERBOSE; + if (strcmp(str, "TRACE") == 0 || + strcmp(str, "T") == 0) { + level = BT_LOG_TRACE; } else if (strcmp(str, "DEBUG") == 0 || strcmp(str, "D") == 0) { level = BT_LOG_DEBUG; @@ -1083,7 +1089,7 @@ int bt_log_get_level_from_string(const char *str) } else if (strcmp(str, "WARN") == 0 || strcmp(str, "WARNING") == 0 || strcmp(str, "W") == 0) { - level = BT_LOG_WARN; + level = BT_LOG_WARNING; } else if (strcmp(str, "ERROR") == 0 || strcmp(str, "E") == 0) { level = BT_LOG_ERROR; @@ -1143,6 +1149,8 @@ end: _level_sym = bt_log_get_level_from_env(_env_var); \ } +#define BT_LOG_SUPPORTED + #ifdef __cplusplus } #endif