@@ -68,9 +68,9 @@ static constexpr Log::Level DEFAULT_LOG_LEVEL = Log::Level::Info;
6868
6969// Packs a level and channel into one 16-bit number.
7070using MessageCategory = u32 ;
71- [[maybe_unused]] ALWAYS_INLINE constexpr u32 PackCategory (Channel channel, Level level, Color colour )
71+ [[maybe_unused]] ALWAYS_INLINE constexpr u32 PackCategory (Channel channel, Level level, Color color )
7272{
73- return ((static_cast <MessageCategory>(colour ) << 10 ) | (static_cast <MessageCategory>(channel) << 3 ) |
73+ return ((static_cast <MessageCategory>(color ) << 10 ) | (static_cast <MessageCategory>(channel) << 3 ) |
7474 static_cast <MessageCategory>(level));
7575}
7676[[maybe_unused]] ALWAYS_INLINE constexpr Color UnpackColor (MessageCategory cat)
@@ -130,7 +130,7 @@ void SetLogChannelEnabled(Channel channel, bool enabled);
130130// Returns the name of the specified log channel.
131131const char * GetChannelName (Channel channel);
132132
133- // Returns the default colour for a log level.
133+ // Returns the default color for a log level.
134134Color GetColorForLevel (Level level);
135135
136136// writes a message to the log
@@ -139,97 +139,52 @@ void Write(MessageCategory cat, const char* functionName, std::string_view messa
139139void WriteFmtArgs (MessageCategory cat, fmt::string_view fmt, fmt::format_args args);
140140void WriteFmtArgs (MessageCategory cat, const char * functionName, fmt::string_view fmt, fmt::format_args args);
141141
142- ALWAYS_INLINE void FastWrite (Channel channel, Level level, std::string_view message)
143- {
144- if (level <= GetLogLevel ()) [[unlikely]]
145- Write (PackCategory (channel, level, Color::Default), message);
146- }
147- ALWAYS_INLINE void FastWrite (Channel channel, const char * functionName, Level level, std::string_view message)
148- {
149- if (level <= GetLogLevel ()) [[unlikely]]
150- Write (PackCategory (channel, level, Color::Default), functionName, message);
151- }
152- template <typename ... T>
153- ALWAYS_INLINE void FastWrite (Channel channel, Level level, fmt::format_string<T...> fmt, T&&... args)
154- {
155- if (level <= GetLogLevel ()) [[unlikely]]
156- WriteFmtArgs (PackCategory (channel, level, Color::Default), fmt, fmt::make_format_args (args...));
157- }
158142template <typename ... T>
159- ALWAYS_INLINE void FastWrite (Channel channel, const char * functionName, Level level, fmt::format_string<T...> fmt,
160- T&&... args)
143+ ALWAYS_INLINE void Write (MessageCategory cat, const char * functionName, fmt::format_string<T...> fmt, T&&... args)
161144{
162- if (level <= GetLogLevel ()) [[unlikely]]
163- WriteFmtArgs (PackCategory (channel, level, Color::Default), functionName, fmt, fmt::make_format_args (args...));
164- }
165- ALWAYS_INLINE void FastWrite (Channel channel, Level level, Color colour, std::string_view message)
166- {
167- if (level <= GetLogLevel ()) [[unlikely]]
168- Write (PackCategory (channel, level, colour), message);
169- }
170- ALWAYS_INLINE void FastWrite (Channel channel, const char * functionName, Level level, Color colour,
171- std::string_view message)
172- {
173- if (level <= GetLogLevel ()) [[unlikely]]
174- Write (PackCategory (channel, level, colour), functionName, message);
175- }
176- template <typename ... T>
177- ALWAYS_INLINE void FastWrite (Channel channel, Level level, Color colour, fmt::format_string<T...> fmt, T&&... args)
178- {
179- if (level <= GetLogLevel ()) [[unlikely]]
180- WriteFmtArgs (PackCategory (channel, level, colour), fmt, fmt::make_format_args (args...));
181- }
182- template <typename ... T>
183- ALWAYS_INLINE void FastWrite (Channel channel, const char * functionName, Level level, Color colour,
184- fmt::format_string<T...> fmt, T&&... args)
185- {
186- if (level <= GetLogLevel ()) [[unlikely]]
187- WriteFmtArgs (PackCategory (channel, level, colour), functionName, fmt, fmt::make_format_args (args...));
145+ WriteFmtArgs (cat, functionName, fmt, fmt::make_format_args (args...));
188146}
147+
189148} // namespace Log
190149
191150// log wrappers
192151#define LOG_CHANNEL (name ) [[maybe_unused]] static constexpr Log::Channel ___LogChannel___ = Log::Channel::name;
193152
194- #define ERROR_LOG (...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Error, __VA_ARGS__)
195- #define WARNING_LOG (...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Warning, __VA_ARGS__)
196- #define INFO_LOG (...) Log::FastWrite(___LogChannel___, Log::Level::Info, __VA_ARGS__)
197- #define VERBOSE_LOG (...) Log::FastWrite(___LogChannel___, Log::Level::Verbose, __VA_ARGS__)
198- #define DEV_LOG (...) Log::FastWrite(___LogChannel___, Log::Level::Dev, __VA_ARGS__)
199-
200- #if defined(_DEBUG) || defined(_DEVEL)
201- #define DEBUG_LOG (...) Log::FastWrite(___LogChannel___, Log::Level::Debug, __VA_ARGS__)
202- #define TRACE_LOG (...) Log::FastWrite(___LogChannel___, Log::Level::Trace, __VA_ARGS__)
203- #else
204- #define DEBUG_LOG (...) \
205- do \
206- { \
207- } while (0 )
208- #define TRACE_LOG (...) \
153+ #define GENERIC_LOG (channel, level, color, ...) \
209154 do \
210155 { \
156+ if ((level) <= Log::GetLogLevel ()) [[unlikely]] \
157+ Log::Write (Log::PackCategory ((channel), (level), (color)), __func__, __VA_ARGS__); \
211158 } while (0 )
212- #endif
213159
214160// clang-format off
215- #define ERROR_COLOR_LOG (colour, ...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Error, Log::Color::colour, __VA_ARGS__)
216- #define WARNING_COLOR_LOG (colour, ...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Warning, Log::Color::colour, __VA_ARGS__)
217- #define INFO_COLOR_LOG (colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Info, Log::Color::colour, __VA_ARGS__)
218- #define VERBOSE_COLOR_LOG (colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Verbose, Log::Color::colour, __VA_ARGS__)
219- #define DEV_COLOR_LOG (colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Dev, Log::Color::colour, __VA_ARGS__)
161+
162+ #define ERROR_LOG (...) GENERIC_LOG(___LogChannel___, Log::Level::Error, Log::Color::Default, __VA_ARGS__)
163+ #define WARNING_LOG (...) GENERIC_LOG(___LogChannel___, Log::Level::Warning, Log::Color::Default, __VA_ARGS__)
164+ #define INFO_LOG (...) GENERIC_LOG(___LogChannel___, Log::Level::Info, Log::Color::Default, __VA_ARGS__)
165+ #define VERBOSE_LOG (...) GENERIC_LOG(___LogChannel___, Log::Level::Verbose, Log::Color::Default, __VA_ARGS__)
166+ #define DEV_LOG (...) GENERIC_LOG(___LogChannel___, Log::Level::Dev, Log::Color::Default, __VA_ARGS__)
220167
221168#if defined(_DEBUG) || defined(_DEVEL)
222- #define DEBUG_COLOR_LOG (colour, ...) Log::FastWrite (___LogChannel___, Log::Level::Debug, Log::Color::colour , __VA_ARGS__)
223- #define TRACE_COLOR_LOG (colour, ...) Log::FastWrite (___LogChannel___, Log::Level::Trace, Log::Color::colour, __VA_ARGS__)
169+ #define DEBUG_LOG ( ...) GENERIC_LOG (___LogChannel___, Log::Level::Debug, Log::Color::Default , __VA_ARGS__)
170+ #define TRACE_LOG ( ...) GENERIC_LOG (___LogChannel___, Log::Level::Trace, Log::Color::Default, __VA_ARGS__)
224171#else
225- #define DEBUG_COLOR_LOG (colour, ...) \
226- do \
227- { \
228- } while (0 )
229- #define TRACE_COLOR_LOG (colour, ...) \
230- do \
231- { \
232- } while (0 )
172+ #define DEBUG_LOG (...) do { } while (0 )
173+ #define TRACE_LOG (...) do { } while (0 )
174+ #endif
175+
176+ #define ERROR_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, __func__, Log::Level::Error, Log::Color::color, __VA_ARGS__)
177+ #define WARNING_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, __func__, Log::Level::Warning, Log::Color::color, __VA_ARGS__)
178+ #define INFO_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, Log::Level::Info, Log::Color::color, __VA_ARGS__)
179+ #define VERBOSE_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, Log::Level::Verbose, Log::Color::color, __VA_ARGS__)
180+ #define DEV_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, Log::Level::Dev, Log::Color::color, __VA_ARGS__)
181+
182+ #if defined(_DEBUG) || defined(_DEVEL)
183+ #define DEBUG_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, Log::Level::Debug, Log::Color::color, __VA_ARGS__)
184+ #define TRACE_COLOR_LOG (color, ...) GENERIC_LOG(___LogChannel___, Log::Level::Trace, Log::Color::color,__VA_ARGS__)
185+ #else
186+ #define DEBUG_COLOR_LOG (color, ...) do { } while (0 )
187+ #define TRACE_COLOR_LOG (color, ...) do { } while (0 )
233188#endif
234189
235190// clang-format on
0 commit comments