SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Logger Class Reference

#include <Logger.hpp>

Static Public Member Functions

static std::shared_ptr< spdlog::logger > & GetCoreLogger ()
 Logger used by engine code (SLEAK_ENGINE builds).
static std::shared_ptr< spdlog::logger > & GetLogger ()
 Logger used by game code.
static void Init (const std::string &ProjectName)
 Creates the console + file sinks and registers both loggers. Call once at startup.

Detailed Description

Sets up the engine and game spdlog sinks. Access via the SLEAK_LOG / SLEAK_INFO / SLEAK_WARN / SLEAK_ERROR macros rather than directly.

Call Init() once from main() before anything else logs, passing your project name. It creates a colored console sink and a file sink, and registers two loggers behind them: one for engine internals and one for game code. The macros pick the right logger automatically based on which target is compiling, so game code and engine code both just use SLEAK_LOG and friends.

Messages use fmt-style {} placeholders, not printf specifiers. The five levels, from quietest to loudest, are SLEAK_LOG (trace), SLEAK_INFO, SLEAK_WARN, SLEAK_ERROR, and SLEAK_FATAL. SLEAK_RETURN_ERR logs at error level and returns false, which suits initialization paths.

int main(int argc, char** argv) {
// ...
}
// Anywhere afterward
SLEAK_INFO("Loaded {} chunks in {:.2f} ms", count, elapsedMs);
SLEAK_WARN("Texture {} is not power of two", path);
bool LoadLevel(const std::string& path) {
if (!Exists(path)) SLEAK_RETURN_ERR("Missing level {}", path);
return true;
}
#define SLEAK_RETURN_ERR(...)
Definition Logger.hpp:25
#define SLEAK_INFO(...)
Definition Logger.hpp:20
#define SLEAK_WARN(...)
Definition Logger.hpp:21
static void Parse(int argc, char **argv)
Parses argv into the value/flag tables. Call once from main(), before Application.
static void Init(const std::string &ProjectName)
Creates the console + file sinks and registers both loggers. Call once at startup.
Definition Logger.cpp:34
See also
Application, CommandLine

Definition at line 68 of file Logger.hpp.

Member Function Documentation

◆ GetCoreLogger()

std::shared_ptr< spdlog::logger > & Sleak::Logger::GetCoreLogger ( )
static

Logger used by engine code (SLEAK_ENGINE builds).

Definition at line 103 of file Logger.cpp.

◆ GetLogger()

std::shared_ptr< spdlog::logger > & Sleak::Logger::GetLogger ( )
static

Logger used by game code.

Definition at line 108 of file Logger.cpp.

◆ Init()

void Sleak::Logger::Init ( const std::string & ProjectName)
static

Creates the console + file sinks and registers both loggers. Call once at startup.

Definition at line 34 of file Logger.cpp.