RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
log_basic.cpp

Default logger, levels, macros and named loggers.

Default logger, levels, macros and named loggers.

#include <RST/RST.hpp>
#include <memory>
int main() {
// ── 1. Init ────────────────────
// ── 2. Logs ───────────────────────────────────────
log->trace("Not shown: the level is Debug");
log->debug("Starting the engine, threads={}", 4);
log->info("Application started, v{}.{}", 1, 0);
log->warn("Low memory: {}MB left", 128);
log->error("File not found: {}", "config.json");
// ── 3. Macros ─────────────
RST_LOG_INFO("RST_LOG_INFO records the file and line");
RST_LOG_WARN("Unexpected value {}", 42);
RST_LOG_ERROR("Critical error in the '{}' module", "Renderer");
// ── 4. Loggers ──────────────────────────────────────────
auto net = RST::Log::Registry::get("Network");
net->info("Connecting to {}:{}", "192.168.1.1", 8080);
net->warn("Timeout after {}ms", 5000);
return 0;
}
#define RST_LOG_INFO(...)
Definition LogRegistry.hpp:75
#define RST_LOG_WARN(...)
Definition LogRegistry.hpp:76
#define RST_LOG_ERROR(...)
Definition LogRegistry.hpp:77
static std::shared_ptr< Logger > init(std::string_view appName="app", LogLevel level=LogLevel::Info, bool toFile=false)
Quick setup: logs from level to the console, and to <appName>.log if toFile is true.
static std::shared_ptr< Logger > get(std::string_view name)
Logger named name, created on first use with the global sinks and level.