63 static constexpr auto values = std::array{
72 static constexpr std::string_view module_name =
"logger_interface";
100 const std::string& msg =
"")
104 ,
timestamp(std::chrono::system_clock::now())
126 std::string_view msg,
131 entry.message = std::string(msg);
132 entry.file = loc.file_name();
133 entry.line = loc.line();
134 entry.function = loc.function_name();
135 entry.timestamp = std::chrono::system_clock::now();
136 entry.location = loc;
187 std::string_view message,
192 return log(level, std::string(message));
253 virtual std::shared_ptr<ILogger>
create_logger(
const std::string& name) = 0;
264 std::string
pattern =
"[%Y-%m-%d %H:%M:%S.%e] [%l] %v";
282class ILoggerRegistry {
299 virtual std::shared_ptr<ILogger>
get_logger(
const std::string& name) = 0;
335 std::string upper(str.size(),
'\0');
336 std::transform(str.begin(), str.end(), upper.begin(),
337 [](
unsigned char c) { return static_cast<char>(std::toupper(c)); });
340 if (upper ==
"WARN") {
343 if (upper ==
"FATAL") {
Result type for error handling with member function support.
Interface for modules that provide logger implementations.
virtual std::shared_ptr< ILogger > create_logger(const std::string &name)=0
Create a new logger with specific name.
virtual std::shared_ptr< ILogger > get_logger()=0
Get the default logger instance.
virtual ~ILoggerProvider()=default
virtual VoidResult register_logger(const std::string &name, std::shared_ptr< ILogger > logger)=0
Register a logger with a name.
virtual VoidResult unregister_logger(const std::string &name)=0
Remove a logger by name.
virtual VoidResult set_default_logger(std::shared_ptr< ILogger > logger)=0
Set the default logger.
virtual ~ILoggerRegistry()=default
virtual std::shared_ptr< ILogger > get_logger(const std::string &name)=0
Get a logger by name.
virtual std::shared_ptr< ILogger > get_default_logger()=0
Get the default logger.
virtual VoidResult log(const log_entry &entry)=0
Log a structured entry.
virtual bool is_enabled(log_level level) const =0
Check if logging is enabled for the specified level.
virtual log_level get_level() const =0
Get the current minimum log level.
virtual VoidResult log(log_level level, std::string_view message, const source_location &loc=source_location::current())
Log a message with source location information (C++20)
virtual ~ILogger()=default
virtual VoidResult set_level(log_level level)=0
Set the minimum log level.
virtual VoidResult flush()=0
Flush any buffered log messages.
virtual VoidResult log(log_level level, const std::string &message)=0
Log a message with specified level.
Generic enum serialization utilities using C++20 concepts.
log_level from_string(const std::string &str)
Parse log level from string (case-insensitive)
std::function< std::shared_ptr< ILogger >()> LoggerFactory
Factory function type for creating logger instances.
std::string to_string(log_level level)
Convert log level to string.
log_level
Standard log levels.
@ warn
Alias for warning (backward compatibility)
@ fatal
Alias for critical (backward compatibility)
Result< Enum > enum_from_string(std::string_view str)
Convert a string to its enum value (case-insensitive)
std::string enum_to_string(Enum value)
Convert an enum value to its string representation.
Umbrella header for Result<T> type and related utilities.
C++17-compatible source_location implementation.
Primary template for enum traits (must be specialized for each enum)
Standard log entry structure.
source_location location
C++20 source_location (Issue #177)
std::chrono::system_clock::time_point timestamp
log_entry(log_level lvl=log_level::info, const std::string &msg="")
Default constructor.
static log_entry create(log_level lvl, std::string_view msg, const source_location &loc=source_location::current())
Factory method to create a log_entry with source_location.
Configuration for logger instances.
logger_config(log_level level, const std::string &fmt="")
C++17-compatible source_location implementation using compiler builtins.
static constexpr source_location current(const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE()) noexcept