diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/logging/logger.hpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/buildtool/logging/logger.hpp b/src/buildtool/logging/logger.hpp index 6d7fd66d..d8e20f6d 100644 --- a/src/buildtool/logging/logger.hpp +++ b/src/buildtool/logging/logger.hpp @@ -107,6 +107,44 @@ class Logger { } } + /// \brief Generic logging method. Provides a common interface between the + /// global logger and named instances, hidden from the outside caller. + /// For named instances no global configuration is used. + template <class... T_Args> + static void Log(Logger const* logger, + LogLevel level, + std::string const& msg, + T_Args&&... args) noexcept { + if (static_cast<int>(level) <= + static_cast<int>(logger != nullptr ? logger->log_limit_ + : LogConfig::LogLimit())) { + FormatAndForward( + logger, + logger != nullptr ? logger->sinks_ : LogConfig::Sinks(), + level, + msg, + std::forward<T_Args>(args)...); + } + } + + /// \brief Generic logging method with provided message creator. Provides a + /// common interface between the global logger and named instances, hidden + /// from the outside caller. + /// For named instances no global configuration is used. + static void Log(Logger const* logger, + LogLevel level, + MessageCreateFunc const& msg_creator) noexcept { + if (static_cast<int>(level) <= + static_cast<int>(logger != nullptr ? logger->log_limit_ + : LogConfig::LogLimit())) { + FormatAndForward( + logger, + logger != nullptr ? logger->sinks_ : LogConfig::Sinks(), + level, + msg_creator()); + } + } + private: std::string name_{}; LogLevel log_limit_{}; |