if (!reopenLogFile()) {
int savederrno = errno;
SLOG(warnlog("Unable to open file '%s' for logging: %s", d_fname, stringerror(savederrno)),
- dnsdist::logging::getTopLogger()->error(Logr::Warning, savederrno, "Unable to open file for logging", "filename", Logging::Loggable(d_fname)));
+ dnsdist::logging::getTopLogger()->error(Logr::Warning, savederrno, "Unable to open file for logging", "path", Logging::Loggable(d_fname)));
}
}
if (!reopenLogFile()) {
int savederrno = errno;
SLOG(warnlog("Unable to open file '%s' for logging: %s", d_fname, stringerror(savederrno)),
- dnsdist::logging::getTopLogger()->error(Logr::Warning, savederrno, "Unable to open file for logging", "filename", Logging::Loggable(d_fname)));
+ dnsdist::logging::getTopLogger()->error(Logr::Warning, savederrno, "Unable to open file for logging", "path", Logging::Loggable(d_fname)));
}
}
}
catch (const std::exception& e) {
SLOG(errlog("Error while opening the verbose logging destination file %s: %s", dest, e.what()),
- context.logger->error(Logr::Error, e.what(), "Error while opening the verbose logging destination file", "filename", Logging::Loggable(dest)));
+ context.logger->error(Logr::Error, e.what(), "Error while opening the verbose logging destination file", "path", Logging::Loggable(dest)));
}
}
// Rust code would be quite cumbersome so for now let's settle for this
s_inConfigCheckMode.store(configCheck);
s_inClientMode.store(isClient);
- auto logger = dnsdist::logging::getTopLogger()->withName("yaml-configuration")->withValues("dnsdist.configuration.file", Logging::Loggable(fileName), "dnsdist.configuration.client_mode", Logging::Loggable(isClient), "dnsdist.configuration.check", Logging::Loggable(configCheck));
+ auto logger = dnsdist::logging::getTopLogger()->withName("yaml-configuration")->withValues("path", Logging::Loggable(fileName), "client_mode", Logging::Loggable(isClient), "configuration_check", Logging::Loggable(configCheck));
Context context{
.logger = logger,
};
auto [poolIt, inserted] = config.d_pools.emplace(std::string(pool.name), ServerPool());
if (inserted) {
VERBOSESLOG(infolog("Creating pool %s", pool.name),
- context.logger->info(Logr::Info, "Creating pool", "pool.name", Logging::Loggable(pool.name)));
+ context.logger->info(Logr::Info, "Creating pool", "pool", Logging::Loggable(pool.name)));
}
if (!pool.packet_cache.empty()) {
}
catch (const ::rust::Error& exp) {
SLOG(errlog("Error while parsing YAML file %s: %s", fileName, exp.what()),
- logger->error(Logr::Error, exp.what(), "Error while parsing YAML file", "dnsdist.configuration.file", Logging::Loggable(fileName)));
+ logger->error(Logr::Error, exp.what(), "Error while parsing YAML file", "path", Logging::Loggable(fileName)));
}
catch (const PDNSException& exp) {
SLOG(errlog("Error while processing YAML configuration from file %s: %s", fileName, exp.reason),
- logger->error(Logr::Error, exp.reason, "Error while processing YAML file", "dnsdist.configuration.file", Logging::Loggable(fileName)));
+ logger->error(Logr::Error, exp.reason, "Error while processing YAML file", "path", Logging::Loggable(fileName)));
}
catch (const std::exception& exp) {
SLOG(errlog("Error while processing YAML configuration from file %s: %s", fileName, exp.what()),
- logger->error(Logr::Error, exp.what(), "Error while processing YAML file", "dnsdist.configuration.file", Logging::Loggable(fileName)));
+ logger->error(Logr::Error, exp.what(), "Error while processing YAML file", "path", Logging::Loggable(fileName)));
}
return false;
#else
logger = logger->withValues("backend.protocol", Logging::Loggable(d_downstream->getProtocol()), "backend.name", Logging::Loggable(d_downstream->getName()), "backend.address", Logging::Loggable(d_downstream->d_config.remote));
}
const double udiff = ids.queryRealTime.udiff();
- logger = logger->withValues("dns.response.latency-us", Logging::Loggable(udiff), "dns.response.size", Logging::Loggable(data.size()));
+ logger = logger->withValues("dns.response.latency_us", Logging::Loggable(udiff), "dns.response.size", Logging::Loggable(data.size()));
return logger;
}
if (!beQuiet) {
SLOG(warnlog("Inserting %s%sdynamic block for %s for %d seconds: %s", dblock.warning ? "(warning) " : "", bpf ? "eBPF " : "", requestor.toString(), dblock.until.tv_sec - now.tv_sec, dblock.reason),
- dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(dblock.warning), "client.address", Logging::Loggable(requestor), "dynamic_rule.use_bpf", Logging::Loggable(bpf), "dyanmic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec)));
+ dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(dblock.warning), "client.address", Logging::Loggable(requestor), "dynamic_rule.use_bpf", Logging::Loggable(bpf), "dynamic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec)));
}
}
if (!beQuiet && (got == nullptr || expired)) {
SLOG(warnlog("Inserting dynamic block for %s for %d seconds: %s", dblock.domain, dblock.until.tv_sec - now.tv_sec, dblock.reason),
- dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(false), "dns.query.name", Logging::Loggable(dblock.domain), "dynamic_rule.use_bpf", Logging::Loggable(false), "dyanmic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec)));
+ dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(false), "dns.query.name", Logging::Loggable(dblock.domain), "dynamic_rule.use_bpf", Logging::Loggable(false), "dynamic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec)));
}
auto domain = dblock.domain;
#ifdef HAVE_LMDB
std::shared_ptr<const Logr::Logger> LMDBKVStore::getLogger() const
{
- return dnsdist::logging::getTopLogger()->withName("lmdb-key-value-store")->withValues("lmdb.filename", Logging::Loggable(d_fname), "lmdb.database", Logging::Loggable(d_dbName));
+ return dnsdist::logging::getTopLogger()->withName("lmdb-key-value-store")->withValues("path", Logging::Loggable(d_fname), "database", Logging::Loggable(d_dbName));
}
bool LMDBKVStore::getValue(const std::string& key, std::string& value)
}
catch (const std::exception& e) {
VERBOSESLOG(infolog("Error while looking up key '%s' from LMDB file '%s', database '%s': %s", key, d_fname, d_dbName, e.what()),
- getLogger()->error(Logr::Info, e.what(), "Error while looking up key", "lmdb.key", Logging::Loggable(key)));
+ getLogger()->error(Logr::Info, e.what(), "Error while looking up key", "key", Logging::Loggable(key)));
}
return false;
}
}
catch (const std::exception& e) {
VERBOSESLOG(infolog("Error while looking up key '%s' from LMDB file '%s', database '%s': %s", key, d_fname, d_dbName, e.what()),
- getLogger()->error(Logr::Info, e.what(), "Error while looking up key", "lmdb.key", Logging::Loggable(key)));
+ getLogger()->error(Logr::Info, e.what(), "Error while looking up key", "key", Logging::Loggable(key)));
}
return false;
}
}
catch (const std::exception& e) {
VERBOSESLOG(infolog("Error while looking up a range from LMDB file '%s', database '%s': %s", d_fname, d_dbName, e.what()),
- getLogger()->error(Logr::Info, e.what(), "Error while looking up a range", "lmdb.key", Logging::Loggable(key)));
+ getLogger()->error(Logr::Info, e.what(), "Error while looking up a range", "key", Logging::Loggable(key)));
}
return false;
}
#ifdef HAVE_CDB
std::shared_ptr<const Logr::Logger> CDBKVStore::getLogger() const
{
- return dnsdist::logging::getTopLogger()->withName("cdb-key-value-store")->withValues("cdb.filename", Logging::Loggable(d_fname));
+ return dnsdist::logging::getTopLogger()->withName("cdb-key-value-store")->withValues("path", Logging::Loggable(d_fname));
}
CDBKVStore::CDBKVStore(const std::string& fname, time_t refreshDelay): d_fname(fname), d_refreshDelay(refreshDelay)
}
catch (const std::exception& e) {
VERBOSESLOG(infolog("Error while looking up key '%s' from CDB file '%s': %s", key, d_fname, e.what()),
- getLogger()->error(Logr::Info, e.what(), "Error while looking up a key", "cdb.key", Logging::Loggable(key)));
+ getLogger()->error(Logr::Info, e.what(), "Error while looking up a key", "key", Logging::Loggable(key)));
}
return false;
}
}
catch (const std::exception& e) {
VERBOSESLOG(infolog("Error while looking up key '%s' from CDB file '%s': %s", key, d_fname, e.what()),
- getLogger()->error(Logr::Info, e.what(), "Error while looking up a key", "cdb.key", Logging::Loggable(key)));
+ getLogger()->error(Logr::Info, e.what(), "Error while looking up a key", "key", Logging::Loggable(key)));
}
return false;
}
if (!poolName.empty()) {
VERBOSESLOG(infolog("Creating pool %s", poolName),
- dnsdist::logging::getTopLogger()->info(Logr::Info, "Creating a new pool of backends", "name", Logging::Loggable(poolName)));
+ dnsdist::logging::getTopLogger()->info(Logr::Info, "Creating a new pool of backends", "pool", Logging::Loggable(poolName)));
}
dnsdist::configuration::updateRuntimeConfiguration([&poolName](dnsdist::configuration::RuntimeConfiguration& config) {
if (created) {
VERBOSESLOG(infolog("Creating pool %s", poolName),
- getLogger("getPool")->info(Logr::Info, "Creating a new pool", "pool.name", Logging::Loggable(poolName)));
+ getLogger("getPool")->info(Logr::Info, "Creating a new pool", "pool", Logging::Loggable(poolName)));
}
return std::make_shared<dnsdist::lua::LuaServerPoolObject>(poolName);
}
catch (const std::exception& e) {
SLOG(errlog("Error while opening the verbose logging destination file %s: %s", dest, e.what()),
- getLogger("setVerboseLogDestination")->error(Logr::Error, e.what(), "Error while opening the verbose logging destination file", "filename", Logging::Loggable(dest)));
+ getLogger("setVerboseLogDestination")->error(Logr::Error, e.what(), "Error while opening the verbose logging destination file", "path", Logging::Loggable(dest)));
}
});
luaCtx.writeFunction("setStructuredLogging", [](bool enable, std::optional<LuaAssociativeTable<std::string>> options) {
if (s_included) {
SLOG(errlog("includeDirectory() cannot be used recursively!"),
- getLogger("includeDirectory")->info(Logr::Error, "includeDirectory cannot be used recursively", "directory", Logging::Loggable(dirname)));
+ getLogger("includeDirectory")->info(Logr::Error, "includeDirectory cannot be used recursively", "path", Logging::Loggable(dirname)));
g_outputBuffer = "includeDirectory() cannot be used recursively!\n";
return;
}
struct stat dirStat{};
if (stat(dirname.c_str(), &dirStat) != 0) {
SLOG(errlog("The included directory %s does not exist!", dirname),
- getLogger("includeDirectory")->info(Logr::Error, "The included directory does not exist", "directory", Logging::Loggable(dirname)));
+ getLogger("includeDirectory")->info(Logr::Error, "The included directory does not exist", "path", Logging::Loggable(dirname)));
g_outputBuffer = "The included directory " + dirname + " does not exist!";
return;
}
if (!S_ISDIR(dirStat.st_mode)) {
SLOG(errlog("The included directory %s is not a directory!", dirname),
- getLogger("includeDirectory")->info(Logr::Error, "The included directory is not a directory", "directory", Logging::Loggable(dirname)));
+ getLogger("includeDirectory")->info(Logr::Error, "The included directory is not a directory", "path", Logging::Loggable(dirname)));
g_outputBuffer = "The included directory " + dirname + " is not a directory!";
return;
}
if (directoryError) {
SLOG(errlog("Error opening included directory: %s!", *directoryError),
- getLogger("includeDirectory")->error(Logr::Error, *directoryError, "Error opening included directory", "directory", Logging::Loggable(dirname)));
+ getLogger("includeDirectory")->error(Logr::Error, *directoryError, "Error opening included directory", "path", Logging::Loggable(dirname)));
g_outputBuffer = "Error opening included directory: " + *directoryError + "!";
return;
}
std::ifstream ifs(file);
if (!ifs) {
SLOG(warnlog("Unable to read configuration from '%s'", file),
- getLogger("includeDirectory")->info(Logr::Warning, "Unable to read configuration from included directory file", "directory", Logging::Loggable(dirname), "filename", Logging::Loggable(file)));
+ getLogger("includeDirectory")->info(Logr::Warning, "Unable to read configuration from included directory file", "path", Logging::Loggable(dirname), "filename", Logging::Loggable(file)));
}
else {
VERBOSESLOG(infolog("Read configuration from '%s'", file),
- getLogger("includeDirectory")->info(Logr::Info, "Read configuration from file", "directory", Logging::Loggable(dirname), "filename", Logging::Loggable(file)));
+ getLogger("includeDirectory")->info(Logr::Info, "Read configuration from file", "path", Logging::Loggable(dirname), "filename", Logging::Loggable(file)));
}
try {
throw std::runtime_error("Unable to read configuration file from " + config);
}
SLOG(warnlog("Unable to read configuration from '%s'", config),
- dnsdist::logging::getTopLogger()->withName("lua-configuration")->info(Logr::Error, "Unable to read configuration from file", "dnsdist.configuration.file", Logging::Loggable(config)));
+ dnsdist::logging::getTopLogger()->withName("lua-configuration")->info(Logr::Error, "Unable to read configuration from file", "path", Logging::Loggable(config)));
}
else {
VERBOSESLOG(infolog("Read configuration from '%s'", config),
- dnsdist::logging::getTopLogger()->withName("lua-configuration")->info(Logr::Info, "Read configuration from file", "dnsdist.configuration.file", Logging::Loggable(config)));
+ dnsdist::logging::getTopLogger()->withName("lua-configuration")->info(Logr::Info, "Read configuration from file", "path", Logging::Loggable(config)));
}
luaCtx.executeCode(ifs);
const auto& ids = currentResponse.d_idstate;
auto udiff = ids.queryRealTime.udiff();
VERBOSESLOG(infolog("Got answer from %s, relayed to %s (%s, %d bytes), took %d us", backend->d_config.remote.toStringWithPort(), ids.origRemote.toStringWithPort(), getProtocol().toString(), sentBytes, udiff),
- ids.getLogger(getLogger())->info(Logr::Info, "Relayed response to client", "backend.name", Logging::Loggable(backend->getName()), "backend.address", Logging::Loggable(backend->d_config.remote), "dns.response.size", Logging::Loggable(sentBytes), "dns.response.latency-us", Logging::Loggable(udiff)));
+ ids.getLogger(getLogger())->info(Logr::Info, "Relayed response to client", "backend.name", Logging::Loggable(backend->getName()), "backend.address", Logging::Loggable(backend->d_config.remote), "dns.response.size", Logging::Loggable(sentBytes), "dns.response.latency_us", Logging::Loggable(udiff)));
auto backendProtocol = backend->getProtocol();
if (backendProtocol == dnsdist::Protocol::DoUDP && !currentResponse.d_idstate.forwardedOverUDP) {
const auto& runtimeConfig = dnsdist::configuration::getCurrentRuntimeConfiguration();
if (!runtimeConfig.d_apiReadWrite) {
SLOG(warnlog("Not writing content to %s since the API is read-only", filebasename),
- logger.info(Logr::Warning, "Not writing content to file since the API is read-only", "filename", Logging::Loggable(filebasename)));
+ logger.info(Logr::Warning, "Not writing content to file since the API is read-only", "path", Logging::Loggable(filebasename)));
return false;
}
if (runtimeConfig.d_apiConfigDirectory.empty()) {
VERBOSESLOG(infolog("Not writing content to %s since the API configuration directory is not set", filebasename),
- logger.info(Logr::Info, "Not writing content to file since the API configuration directory is not set", "filename", Logging::Loggable(filebasename)));
+ logger.info(Logr::Info, "Not writing content to file since the API configuration directory is not set", "path", Logging::Loggable(filebasename)));
return false;
}
if (!ofconf) {
int saved = errno;
SLOG(errlog("Could not open configuration fragment file '%s' for writing: %s", filename, stringerror(saved)),
- logger.error(Logr::Error, saved, "Could not open configuration fragment file for writing", "filename", Logging::Loggable(filebasename)));
+ logger.error(Logr::Error, saved, "Could not open configuration fragment file for writing", "path", Logging::Loggable(filebasename)));
return false;
}
if (ret == -1) {
int error = errno;
VERBOSESLOG(infolog("Error sending UDP response to %s: %s", dest.toStringWithPort(), stringerror(error)),
- dnsdist::logging::getTopLogger()->withName("sendfromto")->error(error, "Error sending UDP response", "destination.address", Logging::Loggable(dest)));
+ dnsdist::logging::getTopLogger()->withName("sendfromto")->error(error, "Error sending UDP response", "client.address", Logging::Loggable(dest)));
}
return;
}
}
catch (const std::exception& exp) {
VERBOSESLOG(infolog("Error sending UDP response from %s to %s: %s", from.toStringWithPort(), dest.toStringWithPort(), exp.what()),
- dnsdist::logging::getTopLogger()->withName("sendfromto")->error(exp.what(), "Error sending UDP response", "source.address", Logging::Loggable(from), "destination.address", Logging::Loggable(dest)));
+ dnsdist::logging::getTopLogger()->withName("sendfromto")->error(exp.what(), "Error sending UDP response", "source.address", Logging::Loggable(from), "client.address", Logging::Loggable(dest)));
}
}
if ((msgh->msg_flags & MSG_TRUNC) != 0) {
/* message was too large for our buffer */
VERBOSESLOG(infolog("Dropping message too large for our buffer"),
- dnsdist::logging::getTopLogger()->info("Dropping query from client that is too large for our buffer", "source.address", Logging::Loggable(dest), "destination.address", Logging::Loggable(clientState.local)));
+ dnsdist::logging::getTopLogger()->info("Dropping query from client that is too large for our buffer", "client.address", Logging::Loggable(remote), "destination.address", Logging::Loggable(dest), "frontend.address", Logging::Loggable(clientState.local)));
++clientState.nonCompliantQueries;
++dnsdist::metrics::g_stats.nonCompliantQueries;
return false;
if (auto tentativeLuaConfFile = lookForTentativeConfigurationFileWithExtension(configurationFile, "lua")) {
VERBOSESLOG(infolog("Loading configuration from auto-discovered Lua file %s", *tentativeLuaConfFile),
- logger->info(Logr::Info, "Loading configuration from auto-discovered Lua file", "dnsdist.configuration.file", Logging::Loggable(*tentativeLuaConfFile)));
+ logger->info(Logr::Info, "Loading configuration from auto-discovered Lua file", "path", Logging::Loggable(*tentativeLuaConfFile)));
dnsdist::configuration::lua::loadLuaConfigurationFile(*(g_lua.lock()), *tentativeLuaConfFile, configCheck);
}
VERBOSESLOG(infolog("Loading configuration from YAML file %s", configurationFile),
- logger->info(Logr::Info, "Loading configuration from YAML file", "dnsdist.configuration.file", Logging::Loggable(configurationFile)));
+ logger->info(Logr::Info, "Loading configuration from YAML file", "path", Logging::Loggable(configurationFile)));
if (!dnsdist::configuration::yaml::loadConfigurationFromFile(configurationFile, isClient, configCheck)) {
return false;
dnsdist::lua::setupLua(*(g_lua.lock()), isClient, configCheck);
if (boost::ends_with(configurationFile, ".lua")) {
VERBOSESLOG(infolog("Loading configuration from Lua file %s", configurationFile),
- logger->info(Logr::Info, "Loading configuration from Lua file", "dnsdist.configuration.file", Logging::Loggable(configurationFile)));
+ logger->info(Logr::Info, "Loading configuration from Lua file", "path", Logging::Loggable(configurationFile)));
dnsdist::configuration::lua::loadLuaConfigurationFile(*(g_lua.lock()), configurationFile, configCheck);
if (auto tentativeYamlConfFile = lookForTentativeConfigurationFileWithExtension(configurationFile, "yml")) {
VERBOSESLOG(infolog("Loading configuration from auto-discovered YAML file %s", *tentativeYamlConfFile),
- logger->info(Logr::Info, "Loading configuration from auto-discovered YAML file", "dnsdist.configuration.file", Logging::Loggable(*tentativeYamlConfFile)));
+ logger->info(Logr::Info, "Loading configuration from auto-discovered YAML file", "path", Logging::Loggable(*tentativeYamlConfFile)));
return dnsdist::configuration::yaml::loadConfigurationFromFile(*tentativeYamlConfFile, isClient, configCheck);
}
}
else {
VERBOSESLOG(infolog("Loading configuration from Lua file %s", configurationFile),
- logger->info(Logr::Info, "Loading configuration from Lua file", "dnsdist.configuration.file", Logging::Loggable(configurationFile)));
+ logger->info(Logr::Info, "Loading configuration from Lua file", "path", Logging::Loggable(configurationFile)));
dnsdist::configuration::lua::loadLuaConfigurationFile(*(g_lua.lock()), configurationFile, configCheck);
}
config.d_structuredLogging = cmdLine.useStructuredLogging;
});
- if (cmdLine.useStructuredLogging) {
+ if (cmdLine.useStructuredLogging && !cmdLine.structuredLoggingBackend.empty()) {
dnsdist::logging::setup(cmdLine.structuredLoggingBackend);
+ setupLogger = dnsdist::logging::getTopLogger()->withName("setup");
}
dnsdist::configuration::updateRuntimeConfiguration([](dnsdist::configuration::RuntimeConfiguration& config) {
}
// No exception was thrown
SLOG(infolog("Configuration '%s' OK!", cmdLine.config),
- setupLogger->info(Logr::Info, "Configuration OK", "dnsdist.configuration.file", Logging::Loggable(cmdLine.config)));
+ setupLogger->info(Logr::Info, "Configuration OK", "path", Logging::Loggable(cmdLine.config)));
doExitNicely();
}
if (ret < 0) {
auto error = errno;
VERBOSESLOG(infolog("Error while sending QUIC datagram of size %d to %s: %s", buffer.size(), peer.toStringWithPort(), stringerror(error)),
- dnsdist::logging::getTopLogger()->error(Logr::Info, error, "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "destination.address", Logging::Loggable(peer)));
+ dnsdist::logging::getTopLogger()->error(Logr::Info, error, "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "client.address", Logging::Loggable(peer)));
}
return;
}
}
catch (const std::exception& exp) {
VERBOSESLOG(infolog("Error while sending QUIC datagram of size %d from %s to %s: %s", buffer.size(), local.toStringWithPort(), peer.toStringWithPort(), exp.what()),
- dnsdist::logging::getTopLogger()->error(Logr::Info, exp.what(), "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "source.address", Logging::Loggable(local), "destination.address", Logging::Loggable(peer)));
+ dnsdist::logging::getTopLogger()->error(Logr::Info, exp.what(), "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "source.address", Logging::Loggable(local), "client.address", Logging::Loggable(peer)));
}
}