Files
aee-arcade/source/utils/log.hpp
T
JailDesignerandClaude Opus 4.7 170521aba6 feat(log): afegeix Log::raw() per a marcadors sense prefix
Recupera el comportament històric dels marcadors "Game start" i "Bye!"
que han de sortir pelats (no com a "App: Game start"). Log::raw(level, msg)
és una variant prima sobre SDL_LogMessage que no anteposa cap tag i cau a
SDL_LOG_CATEGORY_APPLICATION (filtrable per AEE_LOG global).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 09:54:13 +02:00

66 lines
2.5 KiB
C++

#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);
// Variant sense prefix de tag — ús reservat per a marcadors literals
// (p. ex. "Game start" / "Bye!"). Cau a SDL_LOG_CATEGORY_APPLICATION,
// així AEE_LOG global encara els pot silenciar.
void raw(Level lvl, 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