Skip to content

Commit

Permalink
Add getters for log verbosity to espp::Logger and `espp::BaseCompon…
Browse files Browse the repository at this point in the history
…ent` classes (#220)

* feat(logger): add getters for verbosity and rate limit

* feat(base_component): add getter for verbosity
  • Loading branch information
finger563 authored May 2, 2024
1 parent 3e7a18a commit 9badb80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/base_component/include/base_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions components/logger/include/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +106,12 @@ class Logger {
*/
void set_rate_limit(const std::chrono::duration<float> rate_limit) { rate_limit_ = rate_limit; }

/**
* @brief Get the current rate limit for the logger.
* @return The current rate limit.
*/
std::chrono::duration<float> 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
Expand Down

0 comments on commit 9badb80

Please sign in to comment.