diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-03-13 14:54:09 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-03-19 10:31:33 +0100 |
commit | 70bf05ffeb9ef01a72a150abc3e3a4b89f451117 (patch) | |
tree | 38b794d90075d687e35ece05707e13becc010c7b /src | |
parent | 435e473e75f5892b69cf4ad904c3ccf19f8f79dd (diff) | |
download | justbuild-70bf05ffeb9ef01a72a150abc3e3a4b89f451117.tar.gz |
logger: Add common methods for global and named loggers
This allows to be explicit and thus have better control on where
messages get logged.
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_{}; |