From: Charles-Henri Bruyand Date: Fri, 30 Apr 2021 15:22:24 +0000 (+0200) Subject: more constness on the reference children keep on their parents X-Git-Tag: dnsdist-1.7.0-alpha1~122^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0787f02a98d323ff7c9dc84276f93a9795edbe8;p=thirdparty%2Fpdns.git more constness on the reference children keep on their parents --- diff --git a/pdns/recursordist/logging.cc b/pdns/recursordist/logging.cc index 7d1db97897..ec0413a506 100644 --- a/pdns/recursordist/logging.cc +++ b/pdns/recursordist/logging.cc @@ -26,14 +26,14 @@ namespace Logging { - std::shared_ptr Logger::getptr() + std::shared_ptr Logger::getptr() const { return shared_from_this(); } bool Logger::enabled() const { - return true; + return _level <= _verbosity; } void Logger::info(const std::string& msg) const @@ -43,7 +43,7 @@ namespace Logging void Logger::logMessage(const std::string& msg, boost::optional err) const { - if (_level > _verbosity) { + if (!enabled()) { return ; } Entry entry; @@ -70,18 +70,16 @@ namespace Logging logMessage(msg, err); } - std::shared_ptr Logger::v(size_t level) + std::shared_ptr Logger::v(size_t level) const { - auto res = std::make_shared(getptr(), boost::none, level + _level, _callback); - res->setVerbosity(getVerbosity()); + auto res = std::make_shared(getptr(), boost::none, getVerbosity(), level + _level, _callback); return res; } - std::shared_ptr Logger::withValues(const std::string& key, const Logr::Loggable& value) + std::shared_ptr Logger::withValues(const std::string& key, const Logr::Loggable& value) const { - auto res = std::make_shared(getptr(), _name, _level, _callback); + auto res = std::make_shared(getptr(), _name, getVerbosity(), _level, _callback); res->_values.insert({key, value.to_string()}); - res->setVerbosity(getVerbosity()); return res; } @@ -102,13 +100,13 @@ namespace Logging return _t; } - std::shared_ptr Logger::withName(const std::string& name) + std::shared_ptr Logger::withName(const std::string& name) const { std::shared_ptr res; if (_name) { - res = std::make_shared(getptr(), _name.get() + "." + name, _level, _callback); + res = std::make_shared(getptr(), _name.get() + "." + name, getVerbosity(), _level, _callback); } else { - res = std::make_shared(getptr(), name, _level, _callback); + res = std::make_shared(getptr(), name, getVerbosity(), _level, _callback); } res->setVerbosity(getVerbosity()); return res; @@ -138,7 +136,7 @@ namespace Logging Logger::Logger(EntryLogger callback, boost::optional name) : _callback(callback), _name(name) { } - Logger::Logger(std::shared_ptr parent, boost::optional name, size_t lvl, EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl) + Logger::Logger(std::shared_ptr parent, boost::optional name, size_t verbosity, size_t lvl, EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl), _verbosity(verbosity) { } diff --git a/pdns/recursordist/logging.hh b/pdns/recursordist/logging.hh index 58c93dd822..0e07905a64 100644 --- a/pdns/recursordist/logging.hh +++ b/pdns/recursordist/logging.hh @@ -66,7 +66,7 @@ namespace Logging { typedef void(*EntryLogger)(const Entry&); - class Logger: public Logr::Logger, public std::enable_shared_from_this + class Logger: public Logr::Logger, public std::enable_shared_from_this { public: bool enabled() const override; @@ -74,30 +74,32 @@ namespace Logging { void error(int err, const std::string& msg) const override; void error(const std::string& err, const std::string& msg) const override; - std::shared_ptr v(size_t level) override; - std::shared_ptr withValues(const std::string& key, const Logr::Loggable& value) override; - virtual std::shared_ptr withName(const std::string& name) override; + std::shared_ptr v(size_t level) const override; + std::shared_ptr withValues(const std::string& key, const Logr::Loggable& value) const override; + virtual std::shared_ptr withName(const std::string& name) const override; static std::shared_ptr create(EntryLogger callback); static std::shared_ptr create(EntryLogger callback, const std::string& name); Logger(EntryLogger callback); Logger(EntryLogger callback, boost::optional name); - Logger(std::shared_ptr parent, boost::optional name, size_t lvl, EntryLogger callback); + Logger(std::shared_ptr parent, boost::optional name, size_t verbosity, size_t lvl, EntryLogger callback); virtual ~Logger(); size_t getVerbosity() const; void setVerbosity(size_t verbosity); private: void logMessage(const std::string& msg, boost::optional err) const; - std::shared_ptr getptr(); + std::shared_ptr getptr() const; - std::shared_ptr _parent{nullptr}; + std::shared_ptr _parent{nullptr}; EntryLogger _callback; boost::optional _name; std::map _values; - size_t _verbosity{0}; + // current Logger's level. the higher the more verbose. size_t _level{0}; + // verbosity settings. messages with level higher's than verbosity won't appear + size_t _verbosity{0}; }; } diff --git a/pdns/recursordist/logr.hh b/pdns/recursordist/logr.hh index a592c781d7..629a91533b 100644 --- a/pdns/recursordist/logr.hh +++ b/pdns/recursordist/logr.hh @@ -62,17 +62,17 @@ namespace Logr { // this Logger. In other words, V values are additive. V higher verbosity // level means a log message is less important. It's illegal to pass a log // level less than zero. - virtual std::shared_ptr v(size_t level) = 0; + virtual std::shared_ptr v(size_t level) const = 0; // WithValues adds some key-value pairs of context to a logger. // See Info for documentation on how key/value pairs work. - virtual std::shared_ptr withValues(const std::string& key, const Loggable& value) = 0; + virtual std::shared_ptr withValues(const std::string& key, const Loggable& value) const = 0; // WithName adds a new element to the logger's name. // Successive calls with WithName continue to append // suffixes to the logger's name. It's strongly recommended // that name segments contain only letters, digits, and hyphens // (see the package documentation for more information). - virtual std::shared_ptr withName(const std::string& name) = 0; + virtual std::shared_ptr withName(const std::string& name) const = 0; }; }