[Spice-devel] [spice-common v3 01/19] log: simplify log defines with SPICE_LOG
Victor Toso
victortoso at redhat.com
Sat Mar 12 14:32:02 UTC 2016
---
common/log.h | 59 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/common/log.h b/common/log.h
index 0e03f59..68f11ca 100644
--- a/common/log.h
+++ b/common/log.h
@@ -47,47 +47,52 @@ void spice_log(const char *log_domain,
const char *format,
...) SPICE_ATTR_PRINTF(5, 6);
-#define spice_return_if_fail(x) G_STMT_START { \
- if G_LIKELY(x) { } else { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_CRITICAL, SPICE_STRLOC, G_STRFUNC, "condition `%s' failed", #x); \
- return; \
- } \
+
+#define SPICE_LOG(level, format, ...) G_STMT_START { \
+ spice_log(SPICE_LOG_DOMAIN, \
+ (level), \
+ SPICE_STRLOC, \
+ G_STRFUNC, \
+ format, \
+ ## __VA_ARGS__); \
} G_STMT_END
-#define spice_return_val_if_fail(x, val) G_STMT_START { \
- if G_LIKELY(x) { } else { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, "condition `%s' failed", #x); \
- return (val); \
- } \
+#define spice_return_if_fail(x) G_STMT_START { \
+ if G_LIKELY(x) { } else { \
+ SPICE_LOG(SPICE_LOG_LEVEL_CRITICAL, "condition `%s' failed", #x); \
+ return; \
+ } \
} G_STMT_END
-#define spice_warn_if_reached() G_STMT_START { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, "should not be reached"); \
+#define spice_return_val_if_fail(x, val) G_STMT_START { \
+ if G_LIKELY(x) { } else { \
+ SPICE_LOG(SPICE_LOG_LEVEL_CRITICAL, "condition `%s' failed", #x); \
+ return (val); \
+ } \
} G_STMT_END
+
+#define spice_warn_if_reached() \
+ SPICE_LOG(SPICE_LOG_LEVEL_WARNING, "should not be reached")
+
#define spice_printerr(format, ...) G_STMT_START { \
fprintf(stderr, "%s: " format "\n", __FUNCTION__, ## __VA_ARGS__); \
} G_STMT_END
-#define spice_info(format, ...) G_STMT_START { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_INFO, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
-} G_STMT_END
+#define spice_info(format, ...) \
+ SPICE_LOG(SPICE_LOG_LEVEL_INFO, format, ## __VA_ARGS__)
-#define spice_debug(format, ...) G_STMT_START { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_DEBUG, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
-} G_STMT_END
+#define spice_debug(format, ...) \
+ SPICE_LOG(SPICE_LOG_LEVEL_DEBUG, format, ## __VA_ARGS__)
-#define spice_warning(format, ...) G_STMT_START { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
-} G_STMT_END
+#define spice_warning(format, ...) \
+ SPICE_LOG(SPICE_LOG_LEVEL_WARNING, format, ## __VA_ARGS__)
-#define spice_critical(format, ...) G_STMT_START { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
-} G_STMT_END
+#define spice_critical(format, ...) \
+ SPICE_LOG(SPICE_LOG_LEVEL_CRITICAL, format, ## __VA_ARGS__)
-#define spice_error(format, ...) G_STMT_START { \
- spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_ERROR, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
-} G_STMT_END
+#define spice_error(format, ...) \
+ SPICE_LOG(SPICE_LOG_LEVEL_ERROR, format, ## __VA_ARGS__)
#define spice_warn_if_fail(x) G_STMT_START { \
if G_LIKELY(x) { } else { \
--
2.5.0
More information about the Spice-devel
mailing list