Skip to content

Commit

Permalink
Added interface for spdlog (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightwalker-87 committed Dec 24, 2023
1 parent e7f41b2 commit 45c31e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/stlink-lib/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/stlink-lib/spdlog_wrapper.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 45c31e9

Please sign in to comment.