72 lines
2.9 KiB
C++
72 lines
2.9 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);
|
|
|
|
// Com `log`, però antepossa un prefix arbitrari abans del tag, donant
|
|
// "prefix tag: msg". Pensat per a marcadors d'estat (p. ex. claudàtors
|
|
// de càrrega "[ LOADED ]"). El routing per categoria/filtre via AEE_LOG
|
|
// continua actiu (es decideix pel `tag`, no pel prefix).
|
|
void logPrefixed(Level lvl, std::string_view tag, std::string_view prefix, 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
|