aboutsummaryrefslogtreecommitdiff
path: root/libavb
diff options
context:
space:
mode:
authorPierre-Clément Tosi <ptosi@google.com>2023-04-03 13:59:21 +0100
committerPierre-Clément Tosi <ptosi@google.com>2023-04-03 17:34:33 +0100
commite8f7bf5bdb851941c0c891d50941e4a05498ff21 (patch)
treefaf86431c9832364593364646ef228b0eca57c2c /libavb
parente7a3aab1c9043004e6045e0ddddfaa47ca04653b (diff)
downloadavb-e8f7bf5bdb851941c0c891d50941e4a05498ff21.tar.gz
util: Refactor logging macros with AVB_LOG
Centralize the implementation of those macros by sharing AVB_LOG; no functional change intended. Test: - Change-Id: Iffcf1266a91264086be65f9b0b5f1f88557a28db
Diffstat (limited to 'libavb')
-rw-r--r--libavb/avb_util.h74
1 files changed, 21 insertions, 53 deletions
diff --git a/libavb/avb_util.h b/libavb/avb_util.h
index b51cf52..09205fc 100644
--- a/libavb/avb_util.h
+++ b/libavb/avb_util.h
@@ -38,6 +38,14 @@ extern "C" {
#define AVB_STRINGIFY(x) #x
#define AVB_TO_STRING(x) AVB_STRINGIFY(x)
+#define AVB_LOG(level, message, ...) \
+ avb_printv(avb_basename(__FILE__), \
+ ":", \
+ AVB_TO_STRING(__LINE__), \
+ ": " level ": ", \
+ message, \
+ ##__VA_ARGS__)
+
#ifdef AVB_ENABLE_DEBUG
/* Aborts the program if |expr| is false.
*
@@ -63,23 +71,10 @@ extern "C" {
*
* These have no effect unless AVB_ENABLE_DEBUG is defined.
*/
-#define avb_debug(message) \
- do { \
- avb_printv(avb_basename(__FILE__), \
- ":", \
- AVB_TO_STRING(__LINE__), \
- ": DEBUG: ", \
- message, \
- NULL); \
- } while (0)
-#define avb_debugv(message, ...) \
- do { \
- avb_printv(avb_basename(__FILE__), \
- ":", \
- AVB_TO_STRING(__LINE__), \
- ": DEBUG: ", \
- message, \
- ##__VA_ARGS__); \
+#define avb_debug(message) avb_debugv(message, NULL)
+#define avb_debugv(message, ...) \
+ do { \
+ AVB_LOG("DEBUG", message, ##__VA_ARGS__); \
} while (0)
#else
#define avb_assert(expr)
@@ -98,46 +93,19 @@ extern "C" {
/* Prints out a message. This is typically used if a runtime-error
* occurs.
*/
-#define avb_error(message) \
- do { \
- avb_printv(avb_basename(__FILE__), \
- ":", \
- AVB_TO_STRING(__LINE__), \
- ": ERROR: ", \
- message, \
- NULL); \
- } while (0)
-#define avb_errorv(message, ...) \
- do { \
- avb_printv(avb_basename(__FILE__), \
- ":", \
- AVB_TO_STRING(__LINE__), \
- ": ERROR: ", \
- message, \
- ##__VA_ARGS__); \
+#define avb_error(message) avb_errorv(message, NULL)
+#define avb_errorv(message, ...) \
+ do { \
+ AVB_LOG("ERROR", message, ##__VA_ARGS__); \
} while (0)
/* Prints out a message and calls avb_abort().
*/
-#define avb_fatal(message) \
- do { \
- avb_printv(avb_basename(__FILE__), \
- ":", \
- AVB_TO_STRING(__LINE__), \
- ": FATAL: ", \
- message, \
- NULL); \
- avb_abort(); \
- } while (0)
-#define avb_fatalv(message, ...) \
- do { \
- avb_printv(avb_basename(__FILE__), \
- ":", \
- AVB_TO_STRING(__LINE__), \
- ": FATAL: ", \
- message, \
- ##__VA_ARGS__); \
- avb_abort(); \
+#define avb_fatal(message) avb_fatalv(message, NULL)
+#define avb_fatalv(message, ...) \
+ do { \
+ AVB_LOG("FATAL", message, ##__VA_ARGS__); \
+ avb_abort(); \
} while (0)
/* Converts a 16-bit unsigned integer from big-endian to host byte order. */