auto startupLog = g_slog->withName("startup");
if(!::arg().file(configname.c_str())) {
- startupLog
- ->withValues("config_file", Logging::Loggable(configname))
- ->error("No such file", "Unable to parse configuration file");
+ startupLog->error("No such file", "Unable to parse configuration file", "config_file", Logging::Loggable(configname));
}
::arg().parse(argc,argv);
return res;
}
- std::shared_ptr<Logr::Logger> Logger::withValues(const std::string& key, const Logr::Loggable& value) const
+ std::shared_ptr<Logr::Logger> Logger::withValues(const std::map<std::string, std::string>& values) const
{
auto res = std::make_shared<Logger>(getptr(), _name, getVerbosity(), _level, _callback);
- res->_values.insert({key, value.to_string()});
+ res->_values = values;
return res;
}
{
public:
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) const override;
- std::shared_ptr<Logr::Logger> withValues(const std::string& key, const Logr::Loggable& value) const override;
+ std::shared_ptr<Logr::Logger> withValues(const std::map<std::string, std::string>& values) const override;
virtual std::shared_ptr<Logr::Logger> withName(const std::string& name) const override;
static std::shared_ptr<Logger> create(EntryLogger callback);
// keys and arbitrary values.
virtual void info(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);
+ }
+
// 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
// have unique behavior, and should be preferred for logging errors (see the
virtual void error(const std::string& err, const std::string& msg) const = 0;
virtual void error(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(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(err, msg);
+ }
+
// V returns an Logger value for a specific verbosity level, relative to
// 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<Logger> v(size_t level) const = 0;
+ template<typename... Args>
+ std::shared_ptr<Logger> withValues(const std::string& key, const Loggable& value, const Args&... args) const
+ {
+ std::map<std::string, std::string> map = {};
+ this->mapArguments(map, key, value, args...);
+ return this->withValues(map);
+ }
+
// 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<Logger> withValues(const std::string& key, const Loggable& value) const = 0;
+ virtual std::shared_ptr<Logger> withValues(const std::map<std::string, std::string>& values) const = 0;
+
// WithName adds a new element to the logger's name.
// Successive calls with WithName continue to append
// that name segments contain only letters, digits, and hyphens
// (see the package documentation for more information).
virtual std::shared_ptr<Logger> withName(const std::string& name) const = 0;
+
+ private:
+
+ template<typename... Args>
+ void mapArguments(std::map<std::string, std::string>& map, const std::string& key, const Loggable& value, const Args&... args) const
+ {
+ map.emplace(key, value.to_string());
+ mapArguments(map, args...);
+ }
+ void mapArguments(std::map<std::string, std::string>& map) const {
+ return ;
+ }
};
}
static shared_ptr<SOARecordContent> loadRPZFromServer(const ComboAddress& primary, const DNSName& zoneName, std::shared_ptr<DNSFilterEngine::Zone> zone, boost::optional<DNSFilterEngine::Policy> defpol, bool defpolOverrideLocal, uint32_t maxTTL, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, uint16_t axfrTimeout)
{
- auto logger = g_slog->withName("rpz")->withValues("zone", Logging::Loggable(zoneName))->withValues("primary", Logging::Loggable(primary));
+ auto logger = g_slog->withName("rpz")->withValues("zone", Logging::Loggable(zoneName), "primary", Logging::Loggable(primary));
logger->info("Loading RPZ from nameserver");
if(!tt.name.empty()) {
- logger->withValues("tsig_key_name", Logging::Loggable(tt.name))->withValues("tsig_key_algorithm", Logging::Loggable(tt.algo))->info("Using TSIG key for authentication");
+ logger->info("Using TSIG key for authentication", "tsig_key_name", Logging::Loggable(tt.name), "tsig_key_algorithm", Logging::Loggable(tt.algo));
}
ComboAddress local(localAddress);
throw PDNSException("Total AXFR time exceeded!");
}
if(last != time(0)) {
- logger->withValues("nrecords", Logging::Loggable(nrecords))->info("RPZ load in progress");
+ logger->info("RPZ load in progress", "nrecords", Logging::Loggable(nrecords));
last=time(0);
}
}
- logger->withValues("nrecords", Logging::Loggable(nrecords))->withValues("soa", Logging::Loggable(sr->getZoneRepresentation()))->info("RPZ load completed");
+ logger->info("RPZ load completed", "nrecords", Logging::Loggable(nrecords), "soa", Logging::Loggable(sr->getZoneRepresentation()));
return sr;
}
static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr<DNSFilterEngine::Zone>& newZone, const std::string& dumpZoneFileName)
{
auto logger = g_slog->withName("rpz")->withValues("zone", Logging::Loggable(zoneName));
- logger->v(1)->withValues("destination_file", Logging::Loggable(dumpZoneFileName))->info("Dumping zone to disk");
+ logger->v(1)->info("Dumping zone to disk", "destination_file", Logging::Loggable(dumpZoneFileName));
std::string temp = dumpZoneFileName + "XXXXXX";
int fd = mkstemp(&temp.at(0));
if (fd < 0) {
if (rename(temp.c_str(), dumpZoneFileName.c_str()) != 0) {
logger
- ->withValues("destination_file", Logging::Loggable(dumpZoneFileName))
- ->error(errno, "Error while moving the content of the RPZ");
+ ->error(errno, "Error while moving the content of the RPZ", "destination_file", Logging::Loggable(dumpZoneFileName));
return false;
}