return _level <= _verbosity || prio != Logr::Absent;
}
-void Logger::info(const std::string& msg) const
-{
- logMessage(msg, Logr::Absent, std::nullopt);
-}
-
void Logger::info(Logr::Priority prio, const std::string& msg) const
{
logMessage(msg, prio, std::nullopt);
}
-void Logger::logMessage(const std::string& msg, const std::optional<std::string>& err) const
-{
- logMessage(msg, Logr::Absent, err);
-}
-
void Logger::logMessage(const std::string& msg, Logr::Priority prio, const std::optional<std::string>& err) const
{
if (!enabled(prio)) {
logMessage(msg, prio, err);
}
-void Logger::error(int err, const std::string& msg) const
-{
- logMessage(msg, Logr::Absent, std::string(stringerror(err)));
-}
-
-void Logger::error(const std::string& err, const std::string& msg) const
-{
- logMessage(msg, Logr::Absent, err);
-}
-
std::shared_ptr<Logr::Logger> Logger::v(size_t level) const
{
auto res = std::make_shared<Logger>(getptr(), _name, getVerbosity(), level + _level, _callback);
public:
bool enabled(Logr::Priority) const override;
- void info(const std::string& msg) const override;
void info(Logr::Priority, 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;
void error(Logr::Priority, int err, const std::string& msg) const override;
void error(Logr::Priority, const std::string& err, const std::string& msg) const override;
void setVerbosity(size_t verbosity);
private:
- void logMessage(const std::string& msg, const std::optional<std::string>& err) const;
void logMessage(const std::string& msg, Logr::Priority prio, const std::optional<std::string>& err) const;
std::shared_ptr<const Logger> getptr() const;
// A typical use:
//
// SLOG(g_log<<Logger::Warning<<"Unable to parse configuration file '"<<configname<<"'"<<endl,
-// startupLog->error("No such file", "Unable to parse configuration file", "config_file", Logging::Loggable(configname));
+// startupLog->error(Logr::Warning, "No such file", "Unable to parse configuration file", "config_file", Logging::Loggable(configname));
//
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define SLOG(oldStyle, slogCall) \
// 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) const = 0;
virtual void info(Logr::Priority, const std::string& msg) const = 0;
- template <typename... Args>
- void info(const std::string& msg, const std::string& key, const Loggable& value, const Args&... args) const
- {
- auto logger = this->withValues(key, value, args...);
- logger->info(msg);
- }
-
template <typename... Args>
void info(Priority prio, const std::string& msg, const std::string& key, const Loggable& value, const Args&... args) const
{
// 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) const = 0;
- virtual void error(int err, const std::string& msg) const = 0;
virtual void error(Logr::Priority, const std::string& err, const std::string& msg) const = 0;
virtual void error(Logr::Priority, int err, const std::string& msg) const = 0;
- template <typename... Args>
- void error(const std::string& err, const std::string& msg, const std::string& key, const Loggable& value, const Args&... args) const
- {
- auto logger = this->withValues(key, value, args...);
- logger->error(Logr::Absent, err, msg);
- }
-
- template <typename... Args>
- void error(int err, const std::string& msg, const std::string& key, const Loggable& value, const Args&... args) const
- {
- auto logger = this->withValues(key, value, args...);
- logger->error(Logr::Absent, err, msg);
- }
-
template <typename... Args>
void error(Priority prio, const std::string& err, const std::string& msg, const std::string& key, const Loggable& value, const Args&... args) const
{