summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com>2023-12-24 12:26:01 +0100
committernightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com>2023-12-24 12:26:01 +0100
commit45c31e91696db3f44f2fb4aee51ba2c869fa81f7 (patch)
tree6ec8362313795f0ba153c3fe716d96d6332c5502
parente7f41b2965d95eff75114c6f89f13c24cb7357a2 (diff)
Added interface for spdlog (optional)
-rw-r--r--src/stlink-lib/logging.h17
-rw-r--r--src/stlink-lib/spdlog_wrapper.h14
2 files changed, 31 insertions, 0 deletions
diff --git a/src/stlink-lib/logging.h b/src/stlink-lib/logging.h
index cb49a7a..560e20e 100644
--- a/src/stlink-lib/logging.h
+++ b/src/stlink-lib/logging.h
@@ -8,10 +8,16 @@
#ifndef LOGGING_H
#define LOGGING_H
+#include <stdint.h>
+#include "spdlog_wrapper.h"
+
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
+/* Optional: Enable interface for SPDLOG to replace UglyLogging */
+// #define SPDLOG_LOGGING
+
enum ugly_loglevel {
UDEBUG = 90,
UINFO = 50,
@@ -44,6 +50,17 @@ int32_t ugly_libusb_log_level(enum ugly_loglevel v);
#define ELOG_HELPER(format, ...) ugly_log(UERROR, UGLY_LOG_FILE, format, __VA_ARGS__)
#define ELOG(...) ugly_log(UERROR, UGLY_LOG_FILE, __VA_ARGS__)
+#if defined(SPDLOG_LOGGING)
+#undef DLOG_HELPER
+#undef ILOG_HELPER
+#undef WLOG_HELPER
+#undef ELOG_HELPER
+#define DLOG(...) spdlogLog(UDEBUG, __VA_ARGS__)
+#define ILOG(...) spdlogLog(UINFO, __VA_ARGS__)
+#define WLOG(...) spdlogLog(UWARN, __VA_ARGS__)
+#define ELOG(...) spdlogLog(UERROR, __VA_ARGS__)
+#endif // SPDLOG_LOGGING
+
#ifdef __cplusplus
}
#endif // __cplusplus
diff --git a/src/stlink-lib/spdlog_wrapper.h b/src/stlink-lib/spdlog_wrapper.h
new file mode 100644
index 0000000..26f34c8
--- /dev/null
+++ b/src/stlink-lib/spdlog_wrapper.h
@@ -0,0 +1,14 @@
+#ifndef _SPDLOG_WRAPPER_
+#define _SPDLOG_WRAPPER_
+
+#ifdef __cplusplus
+#define EXTERNC extern "C"
+#else
+#define EXTERNC
+#endif
+
+EXTERNC int spdlogLog(int level, const char *str, ...);
+
+#undef EXTERNC
+
+#endif \ No newline at end of file