aboutsummaryrefslogtreecommitdiff
path: root/darwin-bootstrap/ib-log.h
diff options
context:
space:
mode:
Diffstat (limited to 'darwin-bootstrap/ib-log.h')
-rw-r--r--darwin-bootstrap/ib-log.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/darwin-bootstrap/ib-log.h b/darwin-bootstrap/ib-log.h
index fee70b5..c80ae63 100644
--- a/darwin-bootstrap/ib-log.h
+++ b/darwin-bootstrap/ib-log.h
@@ -1,8 +1,13 @@
#pragma once
#include <dispatch/dispatch.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
+#ifdef IB_LOG_TO_SYSLOG
+#include <syslog.h>
+#define ib_log(fmt, args...) syslog(LOG_ERR, IB_LOG_NAME ": " fmt, ##args)
+#else
static FILE *logfp;
static void open_logfp_if_necessary() {
/* syslog() doesn't seem to work from launchd... */
@@ -23,5 +28,17 @@ static void open_logfp_if_necessary() {
fprintf(logfp, fmt "\n", ##args); \
fflush(logfp); \
} while(0)
+#endif
-#define IB_VERBOSE 0
+static inline void ib_log_hex(const void *buf, size_t size) {
+ const uint8_t *up = buf;
+ char *hex = malloc(2 * size + 1), *p = hex;
+ for (size_t i = 0; i < size; i++) {
+ sprintf(p, "%02x", up[i]);
+ p += 2;
+ }
+ ib_log("%s", hex);
+ free(hex);
+}
+
+#define IB_VERBOSE 1