BT_LOG_WRITE_ERRNO(): use `_msg ": %s" _fmt` format
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 19 Jun 2017 23:01:17 +0000 (19:01 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Jul 2017 20:05:42 +0000 (16:05 -0400)
Do not put a period at the end of the errno string: this gives the
opportunity to the user to follow the errno string with a colon, a
space, and fields, e.g.:

    BT_LOGE_ERRNO("Cannot write to file", ": filename=\"%s\"", filename);

which would print this message, for example:

    Cannot write to file: No space left on device: filename="/tmp/my-file"

You can also terminate a field-less message with a period manually:

    BT_LOGE_ERRNO("Cannot close file", ".");

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/logging-internal.h

index 13a36441c56dd29f336ce109440fd666b187bf1b..382e8b80e0f297958ac655bc2ee30f4148526660 100644 (file)
@@ -736,12 +736,12 @@ void _bt_log_write_mem_aux(
  * - BT_LOGF("format string", args, ...)
  *
  * Message and error string (errno) logging macros:
- * - BT_LOGV_ERRNO("format string", args, ...)
- * - BT_LOGD_ERRNO("format string", args, ...)
- * - BT_LOGI_ERRNO("format string", args, ...)
- * - BT_LOGW_ERRNO("format string", args, ...)
- * - BT_LOGE_ERRNO("format string", args, ...)
- * - BT_LOGF_ERRNO("format string", args, ...)
+ * - BT_LOGV_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, ...)
+ * - BT_LOGE_ERRNO("initial message", "format string", args, ...)
+ * - BT_LOGF_ERRNO("initial message", "format string", args, ...)
  *
  * Memory logging macros:
  * - BT_LOGV_MEM(data_ptr, data_sz, "format string", args, ...)
@@ -844,7 +844,7 @@ void _bt_log_write_mem_aux(
                                char error_str[BUFSIZ]; \
                                memset(error_str, 0, sizeof(error_str)); \
                                (void) strerror_r(errno, error_str, sizeof(error_str)); \
-                               BT_LOG_WRITE(lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
+                               BT_LOG_WRITE(lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
                        } _BT_LOG_ONCE
 #else
        /* GNU version of strerror_r(). */
@@ -853,7 +853,7 @@ void _bt_log_write_mem_aux(
                                char error_str_buf[BUFSIZ]; \
                                char *error_str; \
                                error_str = strerror_r(errno, error_str_buf, sizeof(error_str_buf)); \
-                               BT_LOG_WRITE(lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
+                               BT_LOG_WRITE(lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
                        } _BT_LOG_ONCE
 #endif
 
This page took 0.039343 seconds and 4 git commands to generate.