From: Otto Moerbeek Date: Wed, 18 May 2022 11:42:27 +0000 (+0200) Subject: Tweaks: use name for prio, change some prio's, use setter for arguments X-Git-Tag: auth-4.8.0-alpha0~95^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d197c31cac81a2e3e3beb14c932000db508d2831;p=thirdparty%2Fpdns.git Tweaks: use name for prio, change some prio's, use setter for arguments --- diff --git a/pdns/arguments.hh b/pdns/arguments.hh index 96b562580c..1e48ee2b79 100644 --- a/pdns/arguments.hh +++ b/pdns/arguments.hh @@ -77,9 +77,6 @@ class ArgvMap { public: ArgvMap(); -#ifdef RECURSOR - std::shared_ptr 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 { @@ -122,6 +119,12 @@ public: const string &operator[](const string &); //!< iterator semantics const vector&getCommands(); void gatherIncludes(std::vector &extraConfigs); +#ifdef RECURSOR + void setSLog(std::shared_ptr& log) + { + d_log = log; + } +#endif private: void warnIfDeprecated(const string& var); void parseOne(const string &unparsed, const string &parseOnly="", bool lax=false); @@ -133,6 +136,9 @@ private: map d_typeMap; vector d_cmds; std::set d_cleared; +#ifdef RECURSOR + std::shared_ptr d_log; +#endif }; extern ArgvMap &arg(); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 55d55f9b03..5e4cdb9d8f 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2384,7 +2384,7 @@ void makeUDPServerSockets(deferredAdd_t& deferredAdds, std::shared_ptrinfo(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()))); } } diff --git a/pdns/recursordist/logr.hh b/pdns/recursordist/logr.hh index f1ad0931c9..857cc0290b 100644 --- a/pdns/recursordist/logr.hh +++ b/pdns/recursordist/logr.hh @@ -22,6 +22,7 @@ #pragma once +#include #include #include #include @@ -64,6 +65,15 @@ public: // logs. virtual bool enabled(Priority) const = 0; + static std::string toString(Priority arg) + { + const std::array names = {"Absent", "Alert", "Critical", "Error", "Warning", "Notice", "Info", "Debug"}; + auto p = static_cast(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 diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index be46da934b..9adb6a4afc 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -199,7 +199,7 @@ int RecThreadInfo::runThreads(std::shared_ptr& log) 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); @@ -245,14 +245,14 @@ int RecThreadInfo::runThreads(std::shared_ptr& log) // 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); @@ -850,15 +850,15 @@ static void loggerBackend(const Logging::Entry& entry) 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(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))); @@ -1216,7 +1216,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr& lo 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, @@ -1226,7 +1226,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr& lo 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, @@ -1304,7 +1304,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr& lo 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)); } } @@ -1312,7 +1312,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr& lo 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"); @@ -2671,9 +2671,9 @@ int main(int argc, char** argv) 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))); @@ -2732,17 +2732,17 @@ int main(int argc, char** argv) } 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; } diff --git a/pdns/reczones.cc b/pdns/reczones.cc index bcad1a3414..228e70d094 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -226,7 +226,7 @@ static void makeNameToIPZone(std::shared_ptr newMap, const } 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; } @@ -275,7 +275,7 @@ static void makeIPToNamesZone(std::shared_ptr newMap, cons 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; @@ -334,7 +334,7 @@ string reloadZoneConfiguration() 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"] != "") { @@ -479,7 +479,7 @@ std::tuple, std::shared_ptr> 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(fopen(::arg()["forward-zones-file"].c_str(), "r"), fclose); if (!fp) { throw PDNSException("Error opening forward-zones-file '" + ::arg()["forward-zones-file"] + "': " + stringerror()); @@ -537,7 +537,7 @@ std::tuple, std::shared_ptr> } } 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")) { @@ -580,7 +580,7 @@ std::tuple, std::shared_ptr> 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); @@ -617,7 +617,7 @@ std::tuple, std::shared_ptr> 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}; diff --git a/pdns/rpzloader.cc b/pdns/rpzloader.cc index fb88c8d675..d8350bdebe 100644 --- a/pdns/rpzloader.cc +++ b/pdns/rpzloader.cc @@ -327,7 +327,7 @@ static bool dumpZoneToDisk(const shared_ptr& plogger, const DNSNam int fd = mkstemp(&temp.at(0)); if (fd < 0) { SLOG(g_log<error(Logr::Warning, errno, "Unable to create temporary file")); + logger->error(Logr::Error, errno, "Unable to create temporary file")); return false; } @@ -336,7 +336,7 @@ static bool dumpZoneToDisk(const shared_ptr& plogger, const DNSNam int err = errno; close(fd); SLOG(g_log<error(Logr::Warning, err, "Unable to open file pointer")); + logger->error(Logr::Error, err, "Unable to open file pointer")); return false; } @@ -345,7 +345,7 @@ static bool dumpZoneToDisk(const shared_ptr& plogger, const DNSNam } catch(const std::exception& e) { SLOG(g_log<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; } @@ -357,19 +357,19 @@ static bool dumpZoneToDisk(const shared_ptr& plogger, const DNSNam if (fsync(fileno(fp.get())) != 0) { SLOG(g_log<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<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<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; }