@@ -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,106 +130,75 @@ 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
137137void Write (MessageCategory cat, std::string_view message);
138- void Write (MessageCategory cat, const char * functionName , std::string_view message);
138+ void WriteFuncName (MessageCategory cat, const char * function_name , std::string_view message);
139139void WriteFmtArgs (MessageCategory cat, fmt::string_view fmt, fmt::format_args args);
140- void WriteFmtArgs (MessageCategory cat, const char * functionName , fmt::string_view fmt, fmt::format_args args);
140+ void WriteFuncNameFmtArgs (MessageCategory cat, const char * function_name , 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- }
152142template <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- }
158- template <typename ... T>
159- ALWAYS_INLINE void FastWrite (Channel channel, const char * functionName, Level level, fmt::format_string<T...> fmt,
160- T&&... args)
161- {
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)
143+ ALWAYS_INLINE void Write (MessageCategory cat, fmt::format_string<T...> fmt, T&&... args)
166144{
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...));
145+ WriteFmtArgs (cat, fmt, fmt::make_format_args (args...));
181146}
147+
182148template <typename ... T>
183- ALWAYS_INLINE void FastWrite (Channel channel , const char * functionName, Level level, Color colour ,
184- fmt::format_string<T...> fmt, T&&... args)
149+ ALWAYS_INLINE void WriteFuncName (MessageCategory cat , const char * function_name, fmt::format_string<T...> fmt ,
150+ T&&... args)
185151{
186- if (level <= GetLogLevel ()) [[unlikely]]
187- WriteFmtArgs (PackCategory (channel, level, colour), functionName, fmt, fmt::make_format_args (args...));
152+ WriteFuncNameFmtArgs (cat, function_name, fmt, fmt::make_format_args (args...));
188153}
154+
189155} // namespace Log
190156
191157// log wrappers
192158#define LOG_CHANNEL (name ) [[maybe_unused]] static constexpr Log::Channel ___LogChannel___ = Log::Channel::name;
193159
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 (...) \
160+ #define GENERIC_LOG (channel, level, color, ...) \
205161 do \
206162 { \
163+ if ((level) <= Log::GetLogLevel ()) [[unlikely]] \
164+ Log::Write (Log::PackCategory ((channel), (level), (color)), __VA_ARGS__); \
207165 } while (0 )
208- #define TRACE_LOG (...) \
166+
167+ #define GENERIC_FUNC_LOG (channel, level, color, ...) \
209168 do \
210169 { \
170+ if ((level) <= Log::GetLogLevel ()) [[unlikely]] \
171+ Log::WriteFuncName (Log::PackCategory ((channel), (level), (color)), __func__, __VA_ARGS__); \
211172 } while (0 )
212- #endif
213173
214174// 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__)
175+
176+ #define ERROR_LOG (...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Error, Log::Color::Default, __VA_ARGS__)
177+ #define WARNING_LOG (...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Warning, Log::Color::Default, __VA_ARGS__)
178+ #define INFO_LOG (...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Info, Log::Color::Default, __VA_ARGS__)
179+ #define VERBOSE_LOG (...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Verbose, Log::Color::Default, __VA_ARGS__)
180+ #define DEV_LOG (...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Dev, Log::Color::Default, __VA_ARGS__)
220181
221182#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__)
183+ #define DEBUG_LOG ( ...) GENERIC_FUNC_LOG (___LogChannel___, Log::Level::Debug, Log::Color::Default , __VA_ARGS__)
184+ #define TRACE_LOG ( ...) GENERIC_FUNC_LOG (___LogChannel___, Log::Level::Trace, Log::Color::Default, __VA_ARGS__)
224185#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 )
186+ #define DEBUG_LOG (...) do { } while (0 )
187+ #define TRACE_LOG (...) do { } while (0 )
188+ #endif
189+
190+ #define ERROR_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Error, Log::Color::color, __VA_ARGS__)
191+ #define WARNING_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Warning, Log::Color::color, __VA_ARGS__)
192+ #define INFO_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Info, Log::Color::color, __VA_ARGS__)
193+ #define VERBOSE_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Verbose, Log::Color::color, __VA_ARGS__)
194+ #define DEV_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Dev, Log::Color::color, __VA_ARGS__)
195+
196+ #if defined(_DEBUG) || defined(_DEVEL)
197+ #define DEBUG_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Debug, Log::Color::color, __VA_ARGS__)
198+ #define TRACE_COLOR_LOG (color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Trace, Log::Color::color, __VA_ARGS__)
199+ #else
200+ #define DEBUG_COLOR_LOG (color, ...) do { } while (0 )
201+ #define TRACE_COLOR_LOG (color, ...) do { } while (0 )
233202#endif
234203
235204// clang-format on
0 commit comments