diff options
author | comex | 2015-03-01 19:16:24 -0500 |
---|---|---|
committer | comex | 2015-03-01 19:16:24 -0500 |
commit | 8baebb7886a93e71863ac94a24e10477a42c127e (patch) | |
tree | 087e17ae72960dbbc74a369cc7727f881b7dc9c9 /darwin-bootstrap/ib-log.h | |
parent | Let's get hacky! (diff) | |
download | substitute-8baebb7886a93e71863ac94a24e10477a42c127e.tar.gz |
minor changes
Diffstat (limited to 'darwin-bootstrap/ib-log.h')
-rw-r--r-- | darwin-bootstrap/ib-log.h | 19 |
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 |