EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1
7
8#ifndef ECHOMAP_LOGGER_H
9#define ECHOMAP_LOGGER_H
10
11#include <format>
12#include <source_location>
13#include <string_view>
14
15namespace echomap
16{
17
24class Logger
25{
26public:
30 enum class Level
31 {
32 Debug,
33 Info,
34 Warning,
35 Error
36 };
37
45 static void log(
46 Level level,
47 std::string_view message,
49 );
50
60 template <typename... Args>
61 static void log_f(
62 const Level level,
63 const std::source_location location,
64 std::format_string<Args...> fmt,
65 Args&&... args
66 )
67 {
68 log(level, std::format(fmt, std::forward<Args>(args)...), location);
69 }
70
71private:
79};
80
81} // namespace echomap
82
90
91#ifdef NDEBUG
92#define LOG_F_DEBUG(msg, ...)
93#else
94#define LOG_F_DEBUG(msg, ...) \
95 do { \
96 Logger::log_f(Logger::Level::Debug, std::source_location::current(), msg, __VA_ARGS__); \
97 } while (0)
98#endif
99
105#define LOG_F_INFO(msg, ...) \
106 do { \
107 Logger::log_f(Logger::Level::Info, std::source_location::current(), msg, __VA_ARGS__); \
108 } while (0)
109
115#define LOG_F_WARN(msg, ...) \
116 do { \
117 Logger::log_f(Logger::Level::Warning, std::source_location::current(), msg, __VA_ARGS__); \
118 } while (0)
119
125#define LOG_F_ERROR(msg, ...) \
126 do { \
127 Logger::log_f(Logger::Level::Error, std::source_location::current(), msg, __VA_ARGS__); \
128 } while (0)
129
137
138#ifdef NDEBUG
139#define LOG_DEBUG(msg, ...)
140#else
141#define LOG_DEBUG(msg, ...) \
142 do { \
143 Logger::log(Logger::Level::Debug, msg, std::source_location::current()); \
144 } while (0)
145#endif
146
152#define LOG_INFO(msg) \
153 do { \
154 Logger::log(Logger::Level::Info, msg, std::source_location::current()); \
155 } while (0)
156
162#define LOG_WARN(msg) \
163 do { \
164 Logger::log(Logger::Level::Warning, msg, std::source_location::current()); \
165 } while (0)
166
172#define LOG_ERROR(msg) \
173 do { \
174 Logger::log(Logger::Level::Error, msg, std::source_location::current()); \
175 } while (0)
176
177#endif // ECHOMAP_LOGGER_H
A portable (native and browser) and thread-safe logger implementation for formatted messages.
Definition Logger.hpp:25
Level
Indicates the level of importance of a logged message.
Definition Logger.hpp:31
static void log(Level level, std::string_view message, std::source_location location=std::source_location::current())
Log an unformatted message to the backend.
Definition Logger.cpp:22
static std::string_view level_to_string(Level level)
Get a human-readable string corresponding to the given log level.
Definition Logger.cpp:59
static void log_f(const Level level, const std::source_location location, std::format_string< Args... > fmt, Args &&... args)
Log a formatted message to the backend with a specific source location.
Definition Logger.hpp:61
T current(T... args)
T format(T... args)
T forward(T... args)
The main EchoMap outermost namespace for all non-exported symbols.