return shared_from_this();
}
- bool Logger::enabled()
+ bool Logger::enabled() const
{
return true;
}
- void Logger::info(const std::string& msg)
+ void Logger::info(const std::string& msg) const
{
logMessage(msg, boost::none);
}
- void Logger::logMessage(const std::string& msg, boost::optional<const std::string> err)
+ void Logger::logMessage(const std::string& msg, boost::optional<const std::string> err) const
{
if (_level > _verbosity) {
return ;
_callback(entry);
}
- void Logger::error(int err, const std::string& msg)
+ void Logger::error(int err, const std::string& msg) const
{
logMessage(msg, std::string(std::strerror(err)));
}
- void Logger::error(const std::string& err, const std::string& msg)
+ void Logger::error(const std::string& err, const std::string& msg) const
{
logMessage(msg, err);
}
class Logger: public Logr::Logger, public std::enable_shared_from_this<Logger>
{
public:
- bool enabled() override;
- void info(const std::string& msg) override;
- void error(int err, const std::string& msg) override;
- void error(const std::string& err, const std::string& msg) override;
- std::shared_ptr<Logr::Logger> v(size_t level) override;
+ bool enabled() const override;
+ void info(const std::string& msg) const override;
+ 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<Logr::Logger> v(size_t level) override;
std::shared_ptr<Logr::Logger> withValues(const std::string& key, const Logr::Loggable& value) override;
virtual std::shared_ptr<Logr::Logger> withName(const std::string& name) override;
size_t getVerbosity() const;
void setVerbosity(size_t verbosity);
private:
- void logMessage(const std::string& msg, boost::optional<const std::string> err);
+ void logMessage(const std::string& msg, boost::optional<const std::string> err) const;
std::shared_ptr<Logger> getptr();
std::shared_ptr<Logger> _parent{nullptr};
// Enabled tests whether this Logger is enabled. For example, commandline
// flags might be used to set the logging verbosity and disable some info
// logs.
- virtual bool enabled() = 0;
+ virtual bool enabled() const = 0;
// Info logs a non-error message with the given key/value pairs as context.
//
// the log line. The key/value pairs can then be used to add additional
// variable information. The key/value pairs should alternate string
// keys and arbitrary values.
- virtual void info(const std::string& msg) = 0;
+ virtual void info(const std::string& msg) const = 0;
// Error logs an error, with the given message and key/value pairs as context.
// It functions similarly to calling Info with the "error" named value, but may
// The msg field should be used to add context to any underlying error,
// while the err field should be used to attach the actual error that
// triggered this log line, if present.
- virtual void error(const std::string& err, const std::string& msg) = 0;
- virtual void error(int err, const std::string& msg) = 0;
+ virtual void error(const std::string& err, const std::string& msg) const = 0;
+ virtual void error(int err, const std::string& msg) const = 0;
// V returns an Logger value for a specific verbosity level, relative to
// this Logger. In other words, V values are additive. V higher verbosity