Skip to content

EntropyEngine::Core::Logging::Logger

Main logger class that manages sinks and provides logging interface. More…

#include <Logger.h>

Name
template <typename… Args>
void
warning(std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & loc =std::source_location::current())
voidwarning(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())
template <typename… Args>
void
trace(std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & loc =std::source_location::current())
Convenience methods for each log level.
voidtrace(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())
voidsetMinLevel(LogLevel level)
Set minimum log level for this logger.
voidsetGlobal(Logger * logger)
Set a custom global logger.
voidremoveSink(const LogSinkPtr & sink)
Remove a sink from this logger.
voidlog(LogLevel level, std::string_view category, const std::string & message, const std::source_location & location =std::source_location::current())
Core logging function with pre-formatted message.
template <typename… Args>
void
log(LogLevel level, std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & location =std::source_location::current())
Core logging function with format string.
boolisCategoryEnabled(std::string_view category) const
Check if a category is enabled for logging.
template <typename… Args>
void
info(std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & loc =std::source_location::current())
voidinfo(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())
Logger &global()
Get the global logger instance.
LogLevelgetMinLevel() const
Get minimum log level.
voidflush()
Flush all sinks.
template <typename… Args>
void
fatal(std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & loc =std::source_location::current())
voidfatal(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())
template <typename… Args>
void
error(std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & loc =std::source_location::current())
voiderror(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())
voidenableCategory(const std::string & category)
Re-enable logging for a specific category.
voiddisableCategory(const std::string & category)
Disable logging for a specific category.
template <typename… Args>
void
debug(std::string_view category, std::format_string< Args… > fmt, Args &&… args, const std::source_location & loc =std::source_location::current())
voiddebug(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())
voidclearSinks()
Clear all sinks.
voidclearDisabledCategories()
Clear all disabled categories.
voidaddSink(LogSinkPtr sink)
Add a sink to this logger.
Logger(std::string name)
class EntropyEngine::Core::Logging::Logger;

Main logger class that manages sinks and provides logging interface.

Logger serves as the central hub of the logging system. It receives log messages, formats them using std::format, and distributes them to all registered sinks. The logger coordinates multiple output destinations while maintaining thread safety and performance.

Key features:

  • Thread-safe: Supports concurrent logging from multiple threads
  • Multiple sinks: Route logs to various destinations simultaneously
  • Runtime configuration: Modify log levels and sinks dynamically
  • Can be compiled out if needed
  • Modern C++20: Leverages std::format for type-safe formatting
  • Source tracking: Automatic capture of log origin locations

While a single global logger suffices for most applications, multiple loggers can be created for subsystem-specific logging needs.

template <typename... Args>
inline void warning(
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & loc =std::source_location::current()
)
inline void warning(
std::string_view category,
const std::string & message,
const std::source_location & loc =std::source_location::current()
)
template <typename... Args>
inline void trace(
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & loc =std::source_location::current()
)

Convenience methods for each log level.

Direct methods for each severity without specifying LogLevel. Supports both format strings and plain strings.

inline void trace(
std::string_view category,
const std::string & message,
const std::source_location & loc =std::source_location::current()
)
inline void setMinLevel(
LogLevel level
)

Set minimum log level for this logger.

Parameters:

  • level The minimum level to process

Messages below this level are discarded before reaching sinks.

static void setGlobal(
Logger * logger
)

Set a custom global logger.

Parameters:

  • logger Pointer to the new global logger (takes ownership)

Replaces default logger. Useful for testing and custom implementations.

void removeSink(
const LogSinkPtr & sink
)

Remove a sink from this logger.

Parameters:

  • sink The sink to remove

Sink remains valid but no longer receives messages.

inline void log(
LogLevel level,
std::string_view category,
const std::string & message,
const std::source_location & location =std::source_location::current()
)

Core logging function with pre-formatted message.

Parameters:

  • level Message severity level
  • category Subsystem/module category
  • message The log message
  • location Source location (auto-captured)

Source location captured automatically using C++20.

template <typename... Args>
inline void log(
LogLevel level,
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & location =std::source_location::current()
)

Core logging function with format string.

Parameters:

  • level Message severity level
  • category Subsystem/module category
  • fmt Format string (std::format syntax)
  • args Arguments to format
  • location Source location (auto-captured)

Template Parameters:

  • Args Format argument types (deduced automatically)

Uses std::format for type-safe message formatting.

logger.log(LogLevel::Info, "Network", "Connected to {} on port {}",
serverName, portNumber);
inline bool isCategoryEnabled(
std::string_view category
) const

Check if a category is enabled for logging.

Parameters:

  • category The category to check

Return: true if the category is enabled, false if disabled

template <typename... Args>
inline void info(
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & loc =std::source_location::current()
)
inline void info(
std::string_view category,
const std::string & message,
const std::source_location & loc =std::source_location::current()
)
static Logger & global()

Get the global logger instance.

Return: Reference to the global logger

Lazy-initialized on first access. Persists for program lifetime.

// Direct access
Logger::global().info("System", "Application started");
// Preferred macro usage:
ENTROPY_LOG_INFO("Application started");
inline LogLevel getMinLevel() const

Get minimum log level.

Return: The current minimum log level

void flush()

Flush all sinks.

Forces immediate write of buffered data. Called automatically after Fatal messages.

template <typename... Args>
inline void fatal(
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & loc =std::source_location::current()
)
inline void fatal(
std::string_view category,
const std::string & message,
const std::source_location & loc =std::source_location::current()
)
template <typename... Args>
inline void error(
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & loc =std::source_location::current()
)
inline void error(
std::string_view category,
const std::string & message,
const std::source_location & loc =std::source_location::current()
)
inline void enableCategory(
const std::string & category
)

Re-enable logging for a specific category.

Parameters:

  • category The category name to enable
inline void disableCategory(
const std::string & category
)

Disable logging for a specific category.

Parameters:

  • category The category name to disable

Messages from this category will be filtered out regardless of level.

Logger::global().disableCategory("ShaderAsset");
Logger::global().disableCategory("ShaderService");
template <typename... Args>
inline void debug(
std::string_view category,
std::format_string< Args... > fmt,
Args &&... args,
const std::source_location & loc =std::source_location::current()
)
inline void debug(
std::string_view category,
const std::string & message,
const std::source_location & loc =std::source_location::current()
)
void clearSinks()

Clear all sinks.

Messages will be processed but not output. Useful for reconfiguration.

inline void clearDisabledCategories()

Clear all disabled categories.

Re-enables all previously disabled categories.

void addSink(
LogSinkPtr sink
)

Add a sink to this logger.

Parameters:

  • sink The sink to add (shared ownership)

Multiple sinks can be active simultaneously for various destinations.

auto& logger = Logger::global();
logger.addSink(std::make_shared<ConsoleSink>());
logger.addSink(std::make_shared<FileSink>("app.log"));
// Logs now output to both console and file
inline explicit Logger(
std::string name
)

Updated on 2026-01-26 at 17:14:35 -0500