EntropyEngine::Core::Logging::Logger
EntropyEngine::Core::Logging::Logger
Section titled “EntropyEngine::Core::Logging::Logger”Main logger class that manages sinks and provides logging interface. More…
#include <Logger.h>
Public Functions
Section titled “Public Functions”| 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()) |
| void | warning(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. |
| void | trace(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current()) |
| void | setMinLevel(LogLevel level) Set minimum log level for this logger. |
| void | setGlobal(Logger * logger) Set a custom global logger. |
| void | removeSink(const LogSinkPtr & sink) Remove a sink from this logger. |
| 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. |
| 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. |
| bool | isCategoryEnabled(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()) |
| void | info(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current()) |
| Logger & | global() Get the global logger instance. |
| LogLevel | getMinLevel() const Get minimum log level. |
| void | flush() 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()) |
| void | fatal(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()) |
| void | error(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current()) |
| void | enableCategory(const std::string & category) Re-enable logging for a specific category. |
| void | disableCategory(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()) |
| void | debug(std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current()) |
| void | clearSinks() Clear all sinks. |
| void | clearDisabledCategories() Clear all disabled categories. |
| void | addSink(LogSinkPtr sink) Add a sink to this logger. |
| Logger(std::string name) |
Detailed Description
Section titled “Detailed Description”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.
Public Functions Documentation
Section titled “Public Functions Documentation”function warning
Section titled “function warning”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())function warning
Section titled “function warning”inline void warning( std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())function trace
Section titled “function trace”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.
function trace
Section titled “function trace”inline void trace( std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())function setMinLevel
Section titled “function setMinLevel”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.
function setGlobal
Section titled “function setGlobal”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.
function removeSink
Section titled “function removeSink”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.
function log
Section titled “function log”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.
function log
Section titled “function log”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);function isCategoryEnabled
Section titled “function isCategoryEnabled”inline bool isCategoryEnabled( std::string_view category) constCheck if a category is enabled for logging.
Parameters:
- category The category to check
Return: true if the category is enabled, false if disabled
function info
Section titled “function info”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())function info
Section titled “function info”inline void info( std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())function global
Section titled “function global”static Logger & global()Get the global logger instance.
Return: Reference to the global logger
Lazy-initialized on first access. Persists for program lifetime.
// Direct accessLogger::global().info("System", "Application started");
// Preferred macro usage:ENTROPY_LOG_INFO("Application started");function getMinLevel
Section titled “function getMinLevel”inline LogLevel getMinLevel() constGet minimum log level.
Return: The current minimum log level
function flush
Section titled “function flush”void flush()Flush all sinks.
Forces immediate write of buffered data. Called automatically after Fatal messages.
function fatal
Section titled “function fatal”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())function fatal
Section titled “function fatal”inline void fatal( std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())function error
Section titled “function error”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())function error
Section titled “function error”inline void error( std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())function enableCategory
Section titled “function enableCategory”inline void enableCategory( const std::string & category)Re-enable logging for a specific category.
Parameters:
- category The category name to enable
function disableCategory
Section titled “function disableCategory”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");function debug
Section titled “function debug”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())function debug
Section titled “function debug”inline void debug( std::string_view category, const std::string & message, const std::source_location & loc =std::source_location::current())function clearSinks
Section titled “function clearSinks”void clearSinks()Clear all sinks.
Messages will be processed but not output. Useful for reconfiguration.
function clearDisabledCategories
Section titled “function clearDisabledCategories”inline void clearDisabledCategories()Clear all disabled categories.
Re-enables all previously disabled categories.
function addSink
Section titled “function addSink”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 filefunction Logger
Section titled “function Logger”inline explicit Logger( std::string name)Updated on 2026-01-26 at 17:14:35 -0500