Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
log Directory Reference

Directories

 
include
 
src

Detailed Description

`log` — Logging

Type-tagged logging built on spdlog. Singleton Logger with per-type logger registration, console + file output, async mode, and rotation. Integrates with the assert system via a weak-symbol handler when linked.

Public API

Type Purpose
Logger Singleton (Logger::Instance()). Registers backends, routes log calls.
Config Output configuration: console/file patterns, rotation, async settings.
Level kTrace, kDebug, kInfo, kWarn, kError, kCritical.
DefaultLogger Built-in logger type (kName = "HELIOS").
kDefaultLogger Constexpr instance of DefaultLogger.
LoggerTrait Concept: empty struct with static constexpr std::string_view kName.
LoggerWithConfigTrait Extends LoggerTrait with static constexpr Config kConfig.

Free Functions

Convenience wrappers around Logger::Instance():

void Warn(std::string_view message) noexcept
Logs a warning message with the default logger.
Definition logger.hpp:530
void Error(std::string_view message) noexcept
Logs an error message with the default logger.
Definition logger.hpp:577
void Debug(std::string_view) noexcept
Definition logger.hpp:467
void Info(std::string_view message) noexcept
Logs an info message with the default logger.
Definition logger.hpp:483
void Critical(std::string_view message) noexcept
Logs a critical message with the default logger.
Definition logger.hpp:624
void Trace(std::string_view) noexcept
Definition logger.hpp:456

All accept std::format_string overloads and typed-logger variants: Info(MyLogger{}, "msg").

Trace and Debug are compiled out in release builds (HELIOS_RELEASE_MODE).

Quick Start

helios::log::Info("Engine starting");
helios::log::Warn("Low memory: {} MB free", free_mb);
helios::log::Error("Failed to load '{}'", path);

No explicit initialization required — the default logger is created on first use with Config::Debug() (debug) or Config::Release() (release).

Custom Logger Types

struct RenderLogger {
static constexpr std::string_view kName = "Render";
static constexpr auto kConfig = helios::log::Config::ConsoleOnly();
};
helios::log::Info(RenderLogger{}, "Pipeline initialized");
static Logger & Instance() noexcept
Gets the singleton instance.
Definition logger.hpp:53
void AddLogger(T logger, Config config=LoggerConfigOf< T >()) noexcept
Adds a logger with the specified type and configuration.
Definition logger.hpp:282
static constexpr Config ConsoleOnly() noexcept
Creates configuration for console-only output.
Definition config.hpp:61

Configuration

auto config = helios::log::Config{
.log_directory = "logs",
.file_name_pattern = "{name}_{timestamp}.log",
.enable_console = true,
.enable_file = true,
.async_logging = false,
.max_file_size = 10 * 1024 * 1024,
.max_files = 5,
};
// Presets
Configuration for logger behavior and output.
Definition config.hpp:24
static constexpr Config Debug() noexcept
Creates configuration optimized for debug builds.
Definition config.hpp:77
static constexpr Config Default() noexcept
Creates default configuration.
Definition config.hpp:55
static constexpr Config FileOnly() noexcept
Creates configuration for file-only output.
Definition config.hpp:69
static constexpr Config Release() noexcept
Creates configuration optimized for release builds.
Definition config.hpp:88

Runtime Control

logger.SetLevel(helios::log::Level::kWarn);
logger.SetLevel(RenderLogger{}, helios::log::Level::kDebug);
logger.FlushAll();
logger.RemoveLogger(RenderLogger{});

Assert Integration

When the log module is linked, assertion failures route through the log plugin handler (priority: custom handler → log plugin → stderr). On MSVC the handler is registered at initialization; on GCC/Clang it uses a weak symbol.

[](std::string_view condition, const std::source_location& loc,
std::string_view message) noexcept {
helios::log::Critical("Assert: {} | {} [{}:{}]", condition, message,
loc.file_name(), loc.line());
});
void SetAssertionHandler(AssertionHandler handler) noexcept
Sets a custom assertion handler.
Definition assert.hpp:202

Dependencies

  • containerMultiTypeMap for logger registry
  • core — asserts
  • utilsTypeIndex
  • External: spdlog