beeping-core 2.0.0
C++20 library for encoding and decoding data over sound
Loading...
Searching...
No Matches
BeepingDebug.h
1#ifndef __BEEPINGDEBUG__
2#define __BEEPINGDEBUG__
3
4// BeepingDebug.h — Structured logging for beeping-core via spdlog.
5//
6// All logging goes through spdlog with JSON-formatted output to rotating
7// files in logs/. Log level is configurable via BEEPING_LOG_LEVEL env var.
8//
9// Macros: BTRACE, BDEBUG, BINFO, BWARN, BERROR — same interface as before,
10// now backed by spdlog. Auto-initializes on first use.
11
12#include <spdlog/spdlog.h>
13
14namespace BEEPING {
15
16// Initialize the beeping logger (safe to call multiple times).
17// Creates a rotating file logger in logs/ with JSON pattern.
18// Reads BEEPING_LOG_LEVEL env var (trace/debug/info/warn/error, default: warn).
19void initBeepingLogger();
20
21// Shutdown (call from last BEEPING_Destroy)
22void shutdownBeepingLogger();
23
24// Ensure logger is initialized before use
25void ensureBeepingLogger();
26
27} // namespace BEEPING
28
29// Strip path to filename only
30#define BEEPING_FILENAME_ \
31 (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \
32 : __FILE__)
33
34#define BTRACE(fmt, ...) \
35 do { \
36 BEEPING::ensureBeepingLogger(); \
37 spdlog::trace("[{}:{}] " fmt, BEEPING_FILENAME_, \
38 __LINE__ __VA_OPT__(, ) __VA_ARGS__); \
39 } while (0)
40
41#define BDEBUG(fmt, ...) \
42 do { \
43 BEEPING::ensureBeepingLogger(); \
44 spdlog::debug("[{}:{}] " fmt, BEEPING_FILENAME_, \
45 __LINE__ __VA_OPT__(, ) __VA_ARGS__); \
46 } while (0)
47
48#define BINFO(fmt, ...) \
49 do { \
50 BEEPING::ensureBeepingLogger(); \
51 spdlog::info("[{}:{}] " fmt, BEEPING_FILENAME_, \
52 __LINE__ __VA_OPT__(, ) __VA_ARGS__); \
53 } while (0)
54
55#define BWARN(fmt, ...) \
56 do { \
57 BEEPING::ensureBeepingLogger(); \
58 spdlog::warn("[{}:{}] " fmt, BEEPING_FILENAME_, \
59 __LINE__ __VA_OPT__(, ) __VA_ARGS__); \
60 } while (0)
61
62#define BERROR(fmt, ...) \
63 do { \
64 BEEPING::ensureBeepingLogger(); \
65 spdlog::error("[{}:{}] " fmt, BEEPING_FILENAME_, \
66 __LINE__ __VA_OPT__(, ) __VA_ARGS__); \
67 } while (0)
68
69#endif // __BEEPINGDEBUG__