aboutgitcodebugslistschat
path: root/log.h
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2024-06-15 00:25:23 +0200
committerStefano Brivio <sbrivio@redhat.com>2024-06-21 15:32:40 +0200
commitc1140df889aeb90f944c1caabdf6f73522dbb250 (patch)
tree0dca35df181b089e4f128b8d518e3816ba2b1d3c /log.h
parentafd9cdc9bb48fdff18d6506e6f5051de35490397 (diff)
downloadpasst-c1140df889aeb90f944c1caabdf6f73522dbb250.tar
passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.gz
passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.bz2
passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.lz
passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.xz
passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.zst
passt-c1140df889aeb90f944c1caabdf6f73522dbb250.zip
log: Add _perror() logging function variants
In many places, we have direct perror() calls, which completely bypass logging functions and log files. They are definitely convenient: offer similar convenience with _perror() logging variants, so that we can drop those direct perror() calls. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'log.h')
-rw-r--r--log.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/log.h b/log.h
index 77d74a2..6f34e8d 100644
--- a/log.h
+++ b/log.h
@@ -16,11 +16,18 @@
void vlogmsg(int pri, const char *format, va_list ap);
void logmsg(int pri, const char *format, ...)
__attribute__((format(printf, 2, 3)));
+void logmsg_perror(int pri, const char *format, ...)
+ __attribute__((format(printf, 2, 3)));
+
+#define err(...) logmsg( LOG_ERR, __VA_ARGS__)
+#define warn(...) logmsg( LOG_WARNING, __VA_ARGS__)
+#define info(...) logmsg( LOG_INFO, __VA_ARGS__)
+#define debug(...) logmsg( LOG_DEBUG, __VA_ARGS__)
-#define err(...) logmsg(LOG_ERR, __VA_ARGS__)
-#define warn(...) logmsg(LOG_WARNING, __VA_ARGS__)
-#define info(...) logmsg(LOG_INFO, __VA_ARGS__)
-#define debug(...) logmsg(LOG_DEBUG, __VA_ARGS__)
+#define err_perror(...) logmsg_perror( LOG_ERR, __VA_ARGS__)
+#define warn_perror(...) logmsg_perror( LOG_WARNING, __VA_ARGS__)
+#define info_perror(...) logmsg_perror( LOG_INFO, __VA_ARGS__)
+#define debug_perror(...) logmsg_perror( LOG_DEBUG, __VA_ARGS__)
#define die(...) \
do { \
@@ -28,6 +35,12 @@ void logmsg(int pri, const char *format, ...)
exit(EXIT_FAILURE); \
} while (0)
+#define die_perror(...) \
+ do { \
+ err_perror(__VA_ARGS__); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+
extern int log_trace;
extern bool log_conf_parsed;
extern bool log_runtime;