{
public:
ArgvMap();
-#ifdef RECURSOR
- std::shared_ptr<Logr::Logger> d_log;
-#endif
void parse(int &argc, char **argv, bool lax=false); //!< use this to parse from argc and argv
void laxParse(int &argc, char **argv) //!< use this to parse from argc and argv
{
const string &operator[](const string &); //!< iterator semantics
const vector<string>&getCommands();
void gatherIncludes(std::vector<std::string> &extraConfigs);
+#ifdef RECURSOR
+ void setSLog(std::shared_ptr<Logr::Logger>& log)
+ {
+ d_log = log;
+ }
+#endif
private:
void warnIfDeprecated(const string& var);
void parseOne(const string &unparsed, const string &parseOnly="", bool lax=false);
map<string,string> d_typeMap;
vector<string> d_cmds;
std::set<string> d_cleared;
+#ifdef RECURSOR
+ std::shared_ptr<Logr::Logger> d_log;
+#endif
};
extern ArgvMap &arg();
deferredAdds.emplace_back(fd, handleNewUDPQuestion);
g_listenSocketsAddresses[fd] = sin; // this is written to only from the startup thread, not from the workers
SLOG(g_log << Logger::Info << "Listening for UDP queries on " << sin.toStringWithPort() << endl,
- log->info(Logr::Info, "Listening forqueries", "protocol", Logging::Loggable("UDP"), "address", Logging::Loggable(sin.toStringWithPort())));
+ log->info(Logr::Info, "Listening for queries", "protocol", Logging::Loggable("UDP"), "address", Logging::Loggable(sin.toStringWithPort())));
}
}
#pragma once
+#include <array>
#include <string>
#include <memory>
#include <map>
// logs.
virtual bool enabled(Priority) const = 0;
+ static std::string toString(Priority arg)
+ {
+ const std::array<std::string, 8> names = {"Absent", "Alert", "Critical", "Error", "Warning", "Notice", "Info", "Debug"};
+ auto p = static_cast<unsigned int>(arg);
+ if (p >= names.size()) {
+ return "?";
+ }
+ return names.at(p);
+ }
// Info logs a non-error message with the given key/value pairs as context.
//
// The msg argument should be used to add some constant description to
if (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers() == 1) {
SLOG(g_log << Logger::Warning << "Operating with single distributor/worker thread" << endl,
- log->info(Logr::Warning, "Operating with single distributor/worker thread"));
+ log->info(Logr::Notice, "Operating with single distributor/worker thread"));
/* This thread handles the web server, carbon, statistics and the control channel */
auto& handlerInfo = RecThreadInfo::info(0);
// And now start the actual threads
if (RecThreadInfo::weDistributeQueries()) {
SLOG(g_log << Logger::Warning << "Launching " << RecThreadInfo::numDistributors() << " distributor threads" << endl,
- log->info(Logr::Warning, "Launching distributor threads", "count", Logging::Loggable(RecThreadInfo::numDistributors())));
+ log->info(Logr::Notice, "Launching distributor threads", "count", Logging::Loggable(RecThreadInfo::numDistributors())));
for (unsigned int n = 0; n < RecThreadInfo::numDistributors(); ++n) {
auto& info = RecThreadInfo::info(currentThreadId);
info.start(currentThreadId++, "distr", cpusMap);
}
}
SLOG(g_log << Logger::Warning << "Launching " << RecThreadInfo::numWorkers() << " worker threads" << endl,
- log->info(Logr::Warning, "Launching worker threads", "count", Logging::Loggable(RecThreadInfo::numWorkers())));
+ log->info(Logr::Notice, "Launching worker threads", "count", Logging::Loggable(RecThreadInfo::numWorkers())));
for (unsigned int n = 0; n < RecThreadInfo::numWorkers(); ++n) {
auto& info = RecThreadInfo::info(currentThreadId);
buf.str("");
buf << "msg=" << std::quoted(entry.message);
if (entry.error) {
- buf << " oserror=" << std::quoted(entry.error.get());
+ buf << " error=" << std::quoted(entry.error.get());
}
if (entry.name) {
buf << " subsystem=" << std::quoted(entry.name.get());
}
- buf << " level=" << entry.level;
+ buf << " level=" << std::quoted(std::to_string(entry.level));
if (entry.d_priority) {
- buf << " prio=" << static_cast<int>(entry.d_priority);
+ buf << " prio=" << std::quoted(Logr::Logger::toString(entry.d_priority));
}
char timebuf[64];
buf << " ts=" << std::quoted(toTimestampStringMilli(entry.d_timestamp, timebuf, sizeof(timebuf)));
if (pdns::isQueryLocalAddressFamilyEnabled(AF_INET)) {
SyncRes::s_doIPv4 = true;
SLOG(g_log << Logger::Warning << "Enabling IPv4 transport for outgoing queries" << endl,
- log->info(Logr::Warning, "Enabling IPv4 transport for outgoing queries"));
+ log->info(Logr::Notice, "Enabling IPv4 transport for outgoing queries"));
}
else {
SLOG(g_log << Logger::Warning << "NOT using IPv4 for outgoing queries - add an IPv4 address (like '0.0.0.0') to query-local-address to enable" << endl,
if (pdns::isQueryLocalAddressFamilyEnabled(AF_INET6)) {
SyncRes::s_doIPv6 = true;
SLOG(g_log << Logger::Warning << "Enabling IPv6 transport for outgoing queries" << endl,
- log->info(Logr::Warning, "Enabling IPv6 transport for outgoing queries"));
+ log->info(Logr::Notice, "Enabling IPv6 transport for outgoing queries"));
}
else {
SLOG(g_log << Logger::Warning << "NOT using IPv6 for outgoing queries - add an IPv6 address (like '::') to query-local-address to enable" << endl,
g_log << Logger::Warning << endl;
}
else {
- log->info(Logr::Warning, "Will not send queries to", "addresses", Logging::Loggable(ips));
+ log->info(Logr::Notice, "Will not send queries to", "addresses", Logging::Loggable(ips));
}
}
RecThreadInfo::setWeDistributeQueries(::arg().mustDo("pdns-distributes-queries"));
if (RecThreadInfo::weDistributeQueries()) {
SLOG(g_log << Logger::Warning << "PowerDNS Recursor itself will distribute queries over threads" << endl,
- log->info(Logr::Warning, "PowerDNS Recursor itself will distribute queries over threads"));
+ log->info(Logr::Notice, "PowerDNS Recursor itself will distribute queries over threads"));
}
g_outgoingEDNSBufsize = ::arg().asNum("edns-outgoing-bufsize");
g_slog = Logging::Logger::create(loggerBackend);
// Missing: a mechanism to call setVerbosity(x)
- auto startupLog = g_slog->withName("startup");
+ auto startupLog = g_slog->withName("config");
- ::arg().d_log = startupLog;
+ ::arg().setSLog(startupLog);
if (!::arg().file(configname.c_str())) {
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)));
}
catch (const PDNSException& ae) {
SLOG(g_log << Logger::Error << "Exception: " << ae.reason << endl,
- g_slog->withName("startup")->error(Logr::Error, ae.reason, "Exception"));
+ g_slog->withName("config")->error(Logr::Error, ae.reason, "Exception"));
ret = EXIT_FAILURE;
}
catch (const std::exception& e) {
SLOG(g_log << Logger::Error << "STL Exception: " << e.what() << endl,
- g_slog->withName("startup")->error(Logr::Error, e.what(), "STL Exception"));
+ g_slog->withName("config")->error(Logr::Error, e.what(), "STL Exception"));
ret = EXIT_FAILURE;
}
catch (...) {
SLOG(g_log << Logger::Error << "any other exception in main: " << endl,
- g_slog->withName("startup")->error(Logr::Error, "Unknown", "Exception"));
+ g_slog->withName("config")->error(Logr::Error, "Unknown", "Exception"));
ret = EXIT_FAILURE;
}
}
else {
SLOG(g_log << Logger::Warning << "Inserting forward zone '" << dr.d_name << "' based on hosts file" << endl,
- log->info(Logr::Warning, "Inserting forward zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
+ log->info(Logr::Notice, "Inserting forward zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
ad.d_name = dr.d_name;
(*newMap)[ad.d_name] = ad;
}
else {
if (ipparts.size() == 4) {
SLOG(g_log << Logger::Warning << "Inserting reverse zone '" << dr.d_name << "' based on hosts file" << endl,
- log->info(Logr::Warning, "Inserting reverse zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
+ log->info(Logr::Notice, "Inserting reverse zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
}
ad.d_name = dr.d_name;
(*newMap)[ad.d_name] = ad;
try {
SLOG(g_log << Logger::Warning << "Reloading zones, purging data from cache" << endl,
- log->info(Logr::Warning, "Reloading zones, purging data from cache"));
+ log->info(Logr::Notice, "Reloading zones, purging data from cache"));
string configname = ::arg()["config-dir"] + "/recursor.conf";
if (::arg()["config-name"] != "") {
if (!::arg()["forward-zones-file"].empty()) {
SLOG(g_log << Logger::Warning << "Reading zone forwarding information from '" << ::arg()["forward-zones-file"] << "'" << endl,
- log->info(Logr::Warning, "Reading zone forwarding information", "file", Logging::Loggable(::arg()["forward-zones-file"])));
+ log->info(Logr::Notice, "Reading zone forwarding information", "file", Logging::Loggable(::arg()["forward-zones-file"])));
auto fp = std::unique_ptr<FILE, int (*)(FILE*)>(fopen(::arg()["forward-zones-file"].c_str(), "r"), fclose);
if (!fp) {
throw PDNSException("Error opening forward-zones-file '" + ::arg()["forward-zones-file"] + "': " + stringerror());
}
}
SLOG(g_log << Logger::Warning << "Done parsing " << newMap->size() - before << " forwarding instructions from file '" << ::arg()["forward-zones-file"] << "'" << endl,
- log->info(Logr::Warning, "Done parsing forwarding instructions from file", "file", Logging::Loggable(::arg()["forward-zones-file"]), "count", Logging::Loggable(newMap->size() - before)));
+ log->info(Logr::Notice, "Done parsing forwarding instructions from file", "file", Logging::Loggable(::arg()["forward-zones-file"]), "count", Logging::Loggable(newMap->size() - before)));
}
if (::arg().mustDo("export-etc-hosts")) {
if (::arg().mustDo("serve-rfc1918")) {
SLOG(g_log << Logger::Warning << "Inserting rfc 1918 private space zones" << endl,
- log->info(Logr::Warning, "Inserting rfc 1918 private space zones"));
+ log->info(Logr::Notice, "Inserting rfc 1918 private space zones"));
parts.clear();
parts.push_back("127");
makeIPToNamesZone(newMap, parts, log);
newSet->insert(DNSName(line));
}
SLOG(g_log << Logger::Warning << "Done parsing " << newSet->size() - before << " NOTIFY-allowed zones from file '" << anff << "'" << endl,
- log->info(Logr::Warning, "Done parsing NOTIFY-allowed zones from file", "file", Logging::Loggable(anff), "count", Logging::Loggable(newSet->size() - before)));
+ log->info(Logr::Notice, "Done parsing NOTIFY-allowed zones from file", "file", Logging::Loggable(anff), "count", Logging::Loggable(newSet->size() - before)));
}
return {newMap, newSet};
int fd = mkstemp(&temp.at(0));
if (fd < 0) {
SLOG(g_log<<Logger::Warning<<"Unable to open a file to dump the content of the RPZ zone "<<zoneName<<endl,
- logger->error(Logr::Warning, errno, "Unable to create temporary file"));
+ logger->error(Logr::Error, errno, "Unable to create temporary file"));
return false;
}
int err = errno;
close(fd);
SLOG(g_log<<Logger::Warning<<"Unable to open a file pointer to dump the content of the RPZ zone "<<zoneName<<endl,
- logger->error(Logr::Warning, err, "Unable to open file pointer"));
+ logger->error(Logr::Error, err, "Unable to open file pointer"));
return false;
}
}
catch(const std::exception& e) {
SLOG(g_log<<Logger::Warning<<"Error while dumping the content of the RPZ zone "<<zoneName<<": "<<e.what()<<endl,
- logger->error(Logr::Warning, e.what(), "Error while dumping the content of the RPZ"));
+ logger->error(Logr::Error, e.what(), "Error while dumping the content of the RPZ"));
return false;
}
if (fsync(fileno(fp.get())) != 0) {
SLOG(g_log<<Logger::Warning<<"Error while syncing the content of the RPZ zone "<<zoneName<<" to the dump file: "<<stringerror()<<endl,
- logger->error(Logr::Warning, errno, "Error while syncing the content of the RPZ"));
+ logger->error(Logr::Error, errno, "Error while syncing the content of the RPZ"));
return false;
}
if (fclose(fp.release()) != 0) {
SLOG(g_log<<Logger::Warning<<"Error while writing the content of the RPZ zone "<<zoneName<<" to the dump file: "<<stringerror()<<endl,
- logger->error(Logr::Warning, errno, "Error while writing the content of the RPZ"));
+ logger->error(Logr::Error, errno, "Error while writing the content of the RPZ"));
return false;
}
if (rename(temp.c_str(), dumpZoneFileName.c_str()) != 0) {
SLOG(g_log<<Logger::Warning<<"Error while moving the content of the RPZ zone "<<zoneName<<" to the dump file: "<<stringerror()<<endl,
- logger->error(Logr::Warning, errno, "Error while moving the content of the RPZ", "destination_file", Logging::Loggable(dumpZoneFileName)));
+ logger->error(Logr::Error, errno, "Error while moving the content of the RPZ", "destination_file", Logging::Loggable(dumpZoneFileName)));
return false;
}