12#include <unordered_map>
28 [[nodiscard]]
static std::shared_ptr<Logger>
get(std::string_view name);
50 using is_transparent = void;
51 [[nodiscard]] std::size_t operator()(std::string_view name)
const noexcept {
return std::hash<std::string_view>{}(name); }
56 std::shared_ptr<Logger> getOrCreate(std::string_view name);
59 std::unordered_map<std::string, std::shared_ptr<Logger>, NameHash, std::equal_to<>> _loggers;
60 std::vector<std::shared_ptr<ISink>> _globalSinks;
62 bool _initialized =
false;
63 std::atomic<Logger*> _default{
nullptr};
71#define RST_LOG(level, ...) RST_LOG_L(::RST::Log::Registry::defaultLoggerRef(), level, __VA_ARGS__)
73#define RST_LOG_TRACE(...) RST_LOGGER_TRACE(::RST::Log::Registry::defaultLoggerRef(), __VA_ARGS__)
74#define RST_LOG_DEBUG(...) RST_LOGGER_DEBUG(::RST::Log::Registry::defaultLoggerRef(), __VA_ARGS__)
75#define RST_LOG_INFO(...) RST_LOGGER_INFO(::RST::Log::Registry::defaultLoggerRef(), __VA_ARGS__)
76#define RST_LOG_WARN(...) RST_LOGGER_WARN(::RST::Log::Registry::defaultLoggerRef(), __VA_ARGS__)
77#define RST_LOG_ERROR(...) RST_LOGGER_ERROR(::RST::Log::Registry::defaultLoggerRef(), __VA_ARGS__)
78#define RST_LOG_FATAL(...) RST_LOGGER_FATAL(::RST::Log::Registry::defaultLoggerRef(), __VA_ARGS__)
81#if defined(RST_LOG_LEGACY_MACROS)
82# define LOG_TRACE(...) RST_LOG_TRACE(__VA_ARGS__)
83# define LOG_DEBUG(...) RST_LOG_DEBUG(__VA_ARGS__)
84# define LOG_INFO(...) RST_LOG_INFO(__VA_ARGS__)
85# define LOG_WARN(...) RST_LOG_WARN(__VA_ARGS__)
86# define LOG_ERROR(...) RST_LOG_ERROR(__VA_ARGS__)
87# define LOG_FATAL(...) RST_LOG_FATAL(__VA_ARGS__)
Named logger that formats messages and sends them to its sinks; thread-safe.
Definition Logger.hpp:24
Global registry of named loggers, including the default logger used by the RST_LOG_* macros.
Definition LogRegistry.hpp:20
static Registry & instance()
static void reset()
Removes every logger and global sink, and resets the global level.
Registry(const Registry &)=delete
static std::shared_ptr< Logger > defaultLogger()
The logger named default, used by the RST_LOG_* macros.
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.
Registry & operator=(const Registry &)=delete
static void addGlobalSink(std::shared_ptr< ISink > sink)
Adds sink to every logger, current and future.
static Logger & defaultLoggerRef()
Same as defaultLogger(), without the reference counting.
static void setGlobalLevel(LogLevel level)
Sets the level of every logger, current and future.
static std::shared_ptr< Logger > get(std::string_view name)
Logger named name, created on first use with the global sinks and level.
Thread-safe logging: loggers, sinks, patterns and macros.
Definition Terminal.hpp:8
LogLevel
Severity of a message, from Trace to Fatal; Off disables logging.
Definition LogLevel.hpp:11