aboutgitcodebugslistschat
path: root/log.h
diff options
context:
space:
mode:
Diffstat (limited to 'log.h')
-rw-r--r--log.h53
1 files changed, 52 insertions, 1 deletions
diff --git a/log.h b/log.h
index dbab006..c6befe3 100644
--- a/log.h
+++ b/log.h
@@ -6,8 +6,57 @@
#ifndef LOG_H
#define LOG_H
-#include <stdarg.h>
#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef PESTO
+
+#include <errno.h>
+
+#include "common.h"
+
+extern bool debug_flag;
+
+#define msg(...) \
+ do { \
+ FPRINTF(stderr, __VA_ARGS__); \
+ FPRINTF(stderr, "\n"); \
+ } while (0)
+
+#define msg_perror(...) \
+ do { \
+ int errno_ = errno; \
+ FPRINTF(stderr, __VA_ARGS__); \
+ FPRINTF(stderr, ": %s\n", strerror_(errno_)); \
+ } while (0)
+
+#define die(...) \
+ do { \
+ msg(__VA_ARGS__); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+
+#define die_perror(...) \
+ do { \
+ msg_perror(__VA_ARGS__); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+
+#define warn(...) msg(__VA_ARGS__)
+#define warn_perror(...) msg_perror(__VA_ARGS__)
+#define info(...) msg(__VA_ARGS__)
+#define info_perror(...) msg_perror(__VA_ARGS__)
+
+#define debug(...) \
+ do { \
+ if (debug_flag) \
+ msg(__VA_ARGS__); \
+ } while (0)
+
+#else /* !PESTO */
+
+#include <stdarg.h>
#include <stddef.h>
#include <syslog.h>
@@ -109,4 +158,6 @@ void __openlog(const char *ident, int option, int facility);
void logfile_init(const char *name, const char *path, size_t size);
void __setlogmask(int mask);
+#endif /* !PESTO */
+
#endif /* LOG_H */