src/logging/log.h: add BT_LOG_WRITE_CUR_LVL(), BT_LOG_WRITE_ERRNO_CUR_LVL()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 15 Jun 2019 03:29:46 +0000 (23:29 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 20 Jun 2019 18:01:16 +0000 (14:01 -0400)
BT_LOG_WRITE_CUR_LVL() is like BT_LOG_WRITE(), but it compares the
given log level to a current log level parameter instead of
`_BT_LOG_OUTPUT_LEVEL`.

BT_LOG_WRITE_ERRNO_CUR_LVL() is the same thing, but for
BT_LOG_WRITE_ERRNO().

The goal of this is to be able to control which variable contains the
current log level at the call site to achieve per-component log levels.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I670664a7cb465954c2f0f8b3551ea49fd1465e32
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1459
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/logging/log.h

index 7368323d4310bdf314ae50205ae61903ef93940d..c9aa4bad3242c783987c295426bdaa99a5f84813 100644 (file)
@@ -660,6 +660,8 @@ bt_log_spec;
  *
  * See BT_LOG_OUTPUT_LEVEL for details.
  */
+#define BT_LOG_ON_CUR_LVL(lvl, cur_lvl) \
+               (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)
@@ -786,6 +788,9 @@ void _bt_log_write_mem_aux(
  * - BT_LOG_WRITE_MEM_AUX(&log_instance, level, tag, data_ptr, data_sz,
  *                        "format string", args, ...)
  *
+ * Explicit log level, current log level, and tag:
+ * - BT_LOG_WRITE_CUR_LVL(level, cur_level, tag, "format string", args, ...)
+ *
  * Format string follows printf() conventions. Both data_ptr and data_sz could
  * be 0. Tag can be 0 as well. Most compilers will verify that type of arguments
  * match format specifiers in format string.
@@ -799,6 +804,11 @@ void _bt_log_write_mem_aux(
                                if (BT_LOG_ON(lvl)) \
                                        _bt_log_write(lvl, tag, __VA_ARGS__); \
                        } _BT_LOG_ONCE
+       #define BT_LOG_WRITE_CUR_LVL(lvl, cur_lvl, tag, ...) \
+                       do { \
+                               if (BT_LOG_ON_CUR_LVL((lvl), (cur_lvl))) \
+                                       _bt_log_write(lvl, tag, __VA_ARGS__); \
+                       } _BT_LOG_ONCE
        #define BT_LOG_WRITE_MEM(lvl, tag, d, d_sz, ...) \
                        do { \
                                if (BT_LOG_ON(lvl)) \
@@ -821,6 +831,12 @@ void _bt_log_write_mem_aux(
                                        _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
                                                        lvl, tag, __VA_ARGS__); \
                        } _BT_LOG_ONCE
+       #define BT_LOG_WRITE_CUR_LVL(lvl, cur_lvl, tag, ...) \
+                       do { \
+                               if (BT_LOG_ON_CUR_LVL((lvl), (cur_lvl))) \
+                                       _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
+                                                       lvl, tag, __VA_ARGS__); \
+                       } _BT_LOG_ONCE
        #define BT_LOG_WRITE_MEM(lvl, tag, d, d_sz, ...) \
                        do { \
                                if (BT_LOG_ON(lvl)) \
@@ -841,11 +857,16 @@ void _bt_log_write_mem_aux(
                        } _BT_LOG_ONCE
 #endif
 
-#define BT_LOG_WRITE_ERRNO(lvl, tag, _msg, _fmt, args...) \
+#define BT_LOG_WRITE_ERRNO_CUR_LVL(lvl, cur_lvl, tag, _msg, _fmt, args...) \
                do { \
                        const char *error_str; \
                        error_str = g_strerror(errno); \
-                       BT_LOG_WRITE(lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
+                       BT_LOG_WRITE_CUR_LVL(lvl, cur_lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
+               } _BT_LOG_ONCE
+
+#define BT_LOG_WRITE_ERRNO(lvl, tag, _msg, _fmt, args...) \
+               do { \
+                       BT_LOG_WRITE_ERRNO_CUR_LVL(lvl, _BT_LOG_OUTPUT_LEVEL, tag, _msg, _fmt, ## args); \
                } _BT_LOG_ONCE
 
 static _BT_LOG_INLINE void _bt_log_unused(const int dummy, ...) {(void)dummy;}
This page took 0.032156 seconds and 4 git commands to generate.