Rework conditional feature usage
Currently, the infrastructure that we have to enable a flexible
compilation environment has a few issues:
- the allocator configuration is performed at run-time, while the log
configuration is performed at compile-time
- for a standard compile (ie, standard userspace, using
autoconf+automake to build), we need a few pre-defined configuration
options.
This change adds a bit of runtime selection to the logging
infrastructure, to match the allocator setup. We also unify the
compile-time defines into config.h, using MCTP_-prefixed macro names,
allowing integration into other build systems.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/libmctp-log.h b/libmctp-log.h
index 1024913..001374b 100644
--- a/libmctp-log.h
+++ b/libmctp-log.h
@@ -4,44 +4,18 @@
#define _LIBMCTP_LOG_H
/* libmctp-internal logging */
-#ifndef pr_fmt
-#define pr_fmt
-#endif
-#if defined(MCTP_LOG_STDERR)
+/* these should match the syslog-standard LOG_* definitions, for
+ * easier use with syslog */
+#define MCTP_LOG_ERR 3
+#define MCTP_LOG_WARNING 4
+#define MCTP_LOG_NOTICE 5
+#define MCTP_LOG_INFO 6
+#define MCTP_LOG_DEBUG 7
-#include <stdio.h>
-
-#define MCTP_LOG_ERR 0
-#define MCTP_LOG_WARNING 0
-#define MCTP_LOG_NOTICE 0
-#define MCTP_LOG_INFO 0
-#define MCTP_LOG_DEBUG 0
-
-#define mctp_prlog(x, fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
-
-#elif defined(MCTP_LOG_SYSLOG)
-
-#include <syslog.h>
-
-#define MCTP_LOG_ERR LOG_ERR
-#define MCTP_LOG_WARNING LOG_WARNING
-#define MCTP_LOG_NOTICE LOG_NOTICE
-#define MCTP_LOG_INFO LOG_INFO
-#define MCTP_LOG_DEBUG LOG_DEBUG
-
-#define mctp_prlog(x, fmt, ...) syslog(x, fmt, ##__VA_ARGS__)
-
-#elif defined(MCTP_LOG_CUSTOM)
-
-extern void mctp_prlog(int level, const char *fmt, ...)
+void mctp_prlog(int level, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
-
-#else
-#error No log implementation found
-#endif
-
#define mctp_prerr(fmt, ...) mctp_prlog(MCTP_LOG_ERR, fmt, ##__VA_ARGS__)
#define mctp_prwarn(fmt, ...) mctp_prlog(MCTP_LOG_WARNING, fmt, ##__VA_ARGS__)
#define mctp_prinfo(fmt, ...) mctp_prlog(MCTP_LOG_INFO, fmt, ##__VA_ARGS__)