feat(log): introdueix Log:: wrapper sobre SDL_Log
Logger lleuger a source/utils/log.{hpp,cpp} amb API basada en std::format
i filtre runtime via la variable d'entorn AEE_LOG (sintaxi
*:info,Resource::Helper:warn,scene:debug). Substitueix gradualment els
std::cout/cerr dispersos.
- Categories CUSTOM registrades sota demanda; per defecte INFO.
- Categories SDL natives no es toquen tret que l'usuari posi *:level.
- Migra resource_helper.cpp i els marcadors d'inici/fi (main.cpp) com a
testimoni; la resta de subsistemes es migra en commits següents.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c910a16834
commit
1243b457be
5 files changed
+226
-12
No files matched your search
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
// Logger lleuger embolicant `SDL_Log*`. Una sola entrada per nivell, format
|
||||
// type-safe via `std::format`. Filtre runtime amb la variable d'entorn
|
||||
// AEE_LOG (sintaxi `*:info,Resource::Helper:warn,scene:debug`). Ús típic:
|
||||
//
|
||||
// Log::info("Resource::Helper", "pack loaded ({} entries)", n);
|
||||
// Log::warn("Options", "preset \"{}\" no trobat; aplicant defaults.", name);
|
||||
// Log::error("Director", "no s'ha pogut carregar config.yaml a {}", path);
|
||||
//
|
||||
namespace Log {
|
||||
|
||||
enum class Level : std::uint8_t {
|
||||
TRACE,
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
CRITICAL,
|
||||
};
|
||||
|
||||
// Llig AEE_LOG i configura les prioritats SDL. Crida una sola vegada,
|
||||
// tan aviat com sigui possible (abans del primer `Log::*`).
|
||||
void init();
|
||||
|
||||
// Backend usat per les funcions per nivell. Composa "tag: msg" i ho
|
||||
// entrega a SDL_LogMessage amb la categoria registrada per al tag.
|
||||
void log(Level lvl, std::string_view tag, std::string_view msg);
|
||||
|
||||
template <typename... Args>
|
||||
void trace(std::string_view tag, std::format_string<Args...> fmt, Args&&... args) {
|
||||
log(Level::TRACE, tag, std::format(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
template <typename... Args>
|
||||
void debug(std::string_view tag, std::format_string<Args...> fmt, Args&&... args) {
|
||||
log(Level::DEBUG, tag, std::format(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
template <typename... Args>
|
||||
void info(std::string_view tag, std::format_string<Args...> fmt, Args&&... args) {
|
||||
log(Level::INFO, tag, std::format(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
template <typename... Args>
|
||||
void warn(std::string_view tag, std::format_string<Args...> fmt, Args&&... args) {
|
||||
log(Level::WARN, tag, std::format(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
template <typename... Args>
|
||||
void error(std::string_view tag, std::format_string<Args...> fmt, Args&&... args) {
|
||||
log(Level::ERROR, tag, std::format(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
template <typename... Args>
|
||||
void critical(std::string_view tag, std::format_string<Args...> fmt, Args&&... args) {
|
||||
log(Level::CRITICAL, tag, std::format(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
} // namespace Log
|
||||
Reference in new issue
Block a user