From 9badb80410c45dc59ff60304c2e12d09c5726a33 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Thu, 2 May 2024 09:12:33 -0500 Subject: [PATCH] Add getters for log verbosity to `espp::Logger` and `espp::BaseComponent` classes (#220) * feat(logger): add getters for verbosity and rate limit * feat(base_component): add getter for verbosity --- .../base_component/include/base_component.hpp | 14 ++++++++++++++ components/logger/include/logger.hpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/components/base_component/include/base_component.hpp b/components/base_component/include/base_component.hpp index 176cbe3aa..439876c5d 100644 --- a/components/base_component/include/base_component.hpp +++ b/components/base_component/include/base_component.hpp @@ -19,6 +19,12 @@ class BaseComponent { /// \param tag The tag to use for the logger void set_log_tag(const std::string_view &tag) { logger_.set_tag(tag); } + /// Get the log level for the logger + /// \return The verbosity level of the logger + /// \sa Logger::Verbosity + /// \sa Logger::set_verbosity + espp::Logger::Verbosity get_log_level() const { return logger_.get_verbosity(); } + /// Set the log level for the logger /// \param level The verbosity level to use for the logger /// \sa Logger::Verbosity @@ -33,6 +39,14 @@ class BaseComponent { /// \sa Logger::set_verbosity void set_log_verbosity(Logger::Verbosity level) { set_log_level(level); } + /// Get the log verbosity for the logger + /// \return The verbosity level of the logger + /// \note This is a convenience method that calls get_log_level + /// \sa get_log_level + /// \sa Logger::Verbosity + /// \sa Logger::get_verbosity + espp::Logger::Verbosity get_log_verbosity() const { return get_log_level(); } + /// Set the rate limit for the logger /// \param rate_limit The rate limit to use for the logger /// \note Only calls to the logger that have _rate_limit suffix will be rate limited diff --git a/components/logger/include/logger.hpp b/components/logger/include/logger.hpp index 0518e5639..53eaa49d8 100644 --- a/components/logger/include/logger.hpp +++ b/components/logger/include/logger.hpp @@ -59,6 +59,14 @@ class Logger { , rate_limit_(config.rate_limit) , level_(config.level) {} + /** + * @brief Get the current verbosity for the logger. + * @return The current verbosity level. + * \sa Logger::Verbosity + * + */ + Verbosity get_verbosity() const { return level_; } + /** * @brief Change the verbosity for the logger. \sa Logger::Verbosity * @param level new verbosity level @@ -98,6 +106,12 @@ class Logger { */ void set_rate_limit(const std::chrono::duration rate_limit) { rate_limit_ = rate_limit; } + /** + * @brief Get the current rate limit for the logger. + * @return The current rate limit. + */ + std::chrono::duration get_rate_limit() const { return rate_limit_; } + /** * @brief Format args into string according to format string. From: * https://en.cppreference.com/w/cpp/utility/format/format