Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
LogMacros.h
Go to the documentation of this file.
1#pragma once
2
15
16#include "LogCategory.h"
17#include <plog/Log.h>
18#include <format>
19#include <string>
20
21namespace EngineCore
22{
23
27template<typename... Args>
28inline void logImpl(LogCategory& category, LogVerbosity verbosity, const char* file, int line,
29 const char* func, std::format_string<Args...> fmt, Args&&... args)
30{
31 std::string message = std::format(fmt, std::forward<Args>(args)...);
32 std::string fullMessage = std::format("[{}] {}", category.getName(), message);
33
34 // Route to plog with appropriate severity
35 switch (verbosity) {
37 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::fatal).printf("%s", fullMessage.c_str());
38 break;
40 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::error).printf("%s", fullMessage.c_str());
41 break;
43 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::warning).printf("%s", fullMessage.c_str());
44 break;
46 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::info).printf("%s", fullMessage.c_str());
47 break;
49 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::debug).printf("%s", fullMessage.c_str());
50 break;
52 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::verbose).printf("%s", fullMessage.c_str());
53 break;
54 }
55}
56
60inline void logImplSimple(LogCategory& category, LogVerbosity verbosity, const char* file, int line,
61 const char* func, const char* message)
62{
63 std::string fullMessage = std::format("[{}] {}", category.getName(), message);
64
65 switch (verbosity) {
67 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::fatal).printf("%s", fullMessage.c_str());
68 break;
70 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::error).printf("%s", fullMessage.c_str());
71 break;
73 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::warning).printf("%s", fullMessage.c_str());
74 break;
76 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::info).printf("%s", fullMessage.c_str());
77 break;
79 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::debug).printf("%s", fullMessage.c_str());
80 break;
82 PLOG_(PLOG_DEFAULT_INSTANCE_ID, plog::verbose).printf("%s", fullMessage.c_str());
83 break;
84 }
85}
86
87} // namespace EngineCore
88
89// ============================================================================
90// Compile-time verbosity check
91// ============================================================================
92
99#ifndef VS_LOG_COMPILE_TIME_VERBOSITY
100 #ifdef NDEBUG
101 #define VS_LOG_COMPILE_TIME_VERBOSITY ::EngineCore::LogVerbosity::Info
102 #else
103 #define VS_LOG_COMPILE_TIME_VERBOSITY ::EngineCore::LogVerbosity::Verbose
104 #endif
105#endif
106
107// ============================================================================
108// Main Logging Macros
109// ============================================================================
110
122#define VS_LOG(Category, Verbosity, Format, ...) \
123 do { \
124 if constexpr (static_cast<uint8_t>(::EngineCore::LogVerbosity::Verbosity) <= \
125 static_cast<uint8_t>(VS_LOG_COMPILE_TIME_VERBOSITY)) { \
126 if (!Category.isSuppressed(::EngineCore::LogVerbosity::Verbosity)) { \
127 ::EngineCore::logImpl(Category, ::EngineCore::LogVerbosity::Verbosity, \
128 __FILE__, __LINE__, __func__, Format __VA_OPT__(,) __VA_ARGS__); \
129 } \
130 } \
131 } while (0)
132
138#define VS_LOG_SIMPLE(Category, Verbosity, Message) \
139 do { \
140 if constexpr (static_cast<uint8_t>(::EngineCore::LogVerbosity::Verbosity) <= \
141 static_cast<uint8_t>(VS_LOG_COMPILE_TIME_VERBOSITY)) { \
142 if (!Category.isSuppressed(::EngineCore::LogVerbosity::Verbosity)) { \
143 ::EngineCore::logImplSimple(Category, ::EngineCore::LogVerbosity::Verbosity, \
144 __FILE__, __LINE__, __func__, Message); \
145 } \
146 } \
147 } while (0)
148
158#define VS_CLOG(Condition, Category, Verbosity, Format, ...) \
159 do { \
160 if (Condition) { \
161 VS_LOG(Category, Verbosity, Format __VA_OPT__(,) __VA_ARGS__); \
162 } \
163 } while (0)
164
168#define VS_LOG_ONCE(Category, Verbosity, Format, ...) \
169 do { \
170 static bool _vs_logged_once = false; \
171 if (!_vs_logged_once) { \
172 _vs_logged_once = true; \
173 VS_LOG(Category, Verbosity, Format __VA_OPT__(,) __VA_ARGS__); \
174 } \
175 } while (0)
176
177// ============================================================================
178// Convenience Macros (shorter names for common verbosity levels)
179// ============================================================================
180
181#define VS_LOG_FATAL(Category, Format, ...) VS_LOG(Category, Fatal, Format __VA_OPT__(,) __VA_ARGS__)
182#define VS_LOG_ERROR(Category, Format, ...) VS_LOG(Category, Error, Format __VA_OPT__(,) __VA_ARGS__)
183#define VS_LOG_WARNING(Category, Format, ...) VS_LOG(Category, Warning, Format __VA_OPT__(,) __VA_ARGS__)
184#define VS_LOG_INFO(Category, Format, ...) VS_LOG(Category, Info, Format __VA_OPT__(,) __VA_ARGS__)
185#define VS_LOG_DEBUG(Category, Format, ...) VS_LOG(Category, Debug, Format __VA_OPT__(,) __VA_ARGS__)
186#define VS_LOG_VERBOSE(Category, Format, ...) VS_LOG(Category, Verbose, Format __VA_OPT__(,) __VA_ARGS__)
Represents a single log category with verbosity control.
Definition LogCategory.h:89
const char * getName() const
Get the category name.
Log category system implementation.
void logImplSimple(LogCategory &category, LogVerbosity verbosity, const char *file, int line, const char *func, const char *message)
Internal helper for messages without format arguments.
Definition LogMacros.h:60
void logImpl(LogCategory &category, LogVerbosity verbosity, const char *file, int line, const char *func, std::format_string< Args... > fmt, Args &&... args)
Internal helper to format and output a log message.
Definition LogMacros.h:28
LogVerbosity
Log verbosity levels, ordered from most to least severe.
Definition LogCategory.h:28
@ Warning
Potential issue.
Definition LogCategory.h:31
@ Info
Important state changes.
Definition LogCategory.h:32
@ Fatal
Unrecoverable error, may crash.
Definition LogCategory.h:29
@ Error
Recoverable error.
Definition LogCategory.h:30
@ Debug
Development debugging.
Definition LogCategory.h:33
@ Verbose
Detailed tracing.
Definition LogCategory.h:34