From: Otto Moerbeek Date: Fri, 29 Sep 2023 09:33:01 +0000 (+0200) Subject: rec: more log (level) fixes X-Git-Tag: rec-5.0.0-alpha2~23^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c42e89586f16f2816e3585671877a7a87846873c;p=thirdparty%2Fpdns.git rec: more log (level) fixes Found while working on a list --- diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index 04c538025c..6ba031e9e1 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -22,6 +22,7 @@ #include "lua-recursor4.hh" #include #include "logger.hh" +#include "logging.hh" #include "dnsparser.hh" #include "syncres.hh" #include "namespaces.hh" @@ -346,7 +347,8 @@ void RecursorLua4::postPrepareContext() } } catch(std::exception& e) { - g_log <withName("lua")->error(Logr::Error, e.what(), "Error in call to DNSSuffixMatchGroup:add")); } } ); @@ -501,7 +503,8 @@ void RecursorLua4::getFeatures(Features& features) static void warnDrop(const RecursorLua4::DNSQuestion& dq) { if (dq.rcode == -2) { - g_log << Logger::Error << "Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics" << endl; + SLOG(g_log << Logger::Error << "Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics" << endl, + g_slog->withName("lua")->info(Logr::Error,"Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics")); // We *could* set policy here, but that would also mean interfering with rcode and the return code of the hook. // So leave it at the error message. } @@ -744,7 +747,8 @@ bool RecursorLua4::genhook(const luacall_t& func, DNSQuestion& dq, int& ret) con dq.udpAnswer = std::string(reinterpret_cast(p.data()), p.size()); auto cbFunc = d_lw->readVariable>(dq.udpCallback).get_value_or(0); if (!cbFunc) { - g_log << Logger::Error << "Attempted callback for Lua UDP Query/Response which could not be found" << endl; + SLOG(g_log << Logger::Error << "Attempted callback for Lua UDP Query/Response which could not be found" << endl, + g_slog->withName("lua")->info(Logr::Error, "Attempted callback for Lua UDP Query/Response which could not be found")); return false; } bool result = cbFunc(&dq); diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index 3eafd3f69c..6ecbce1b78 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -1882,7 +1882,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi } catch (const std::exception& e) { SLOG(g_log << Logger::Error << "STL error " << makeLoginfo(comboWriter) << ": " << e.what(), - resolver.d_slog->error(Logr::Error, e.what(), "Exception in resolver context ", "exception", Logging::Loggable("std::exception"))); + resolver.d_slog->error(Logr::Error, e.what(), "Exception in resolver context", "exception", Logging::Loggable("std::exception"))); // Luawrapper nests the exception from Lua, so we unnest it here try { @@ -2624,8 +2624,8 @@ void makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log) #endif if (address.sin6.sin6_family == AF_INET6 && setsockopt(socketFd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)) < 0) { int err = errno; - SLOG(g_log << Logger::Error << "Failed to set IPv6 socket to IPv6 only, continuing anyhow: " << stringerror(err) << endl, - log->error(Logr::Error, "Failed to set IPv6 socket to IPv6 only, continuing anyhow")); + SLOG(g_log << Logger::Warning << "Failed to set IPv6 socket to IPv6 only, continuing anyhow: " << stringerror(err) << endl, + log->error(Logr::Warning, "Failed to set IPv6 socket to IPv6 only, continuing anyhow")); } } if (::arg().mustDo("non-local-bind")) { @@ -2755,7 +2755,7 @@ void distributeAsyncFunction(const string& packet, const pipefunc_t& func) { if (!RecThreadInfo::self().isDistributor()) { SLOG(g_log << Logger::Error << "distributeAsyncFunction() has been called by a worker (" << RecThreadInfo::id() << ")" << endl, - g_slog->info(Logr::Error, "distributeAsyncFunction() has been called by a worker")); // tid will be added + g_slog->withName("runtime")->info(Logr::Error, "distributeAsyncFunction() has been called by a worker")); // tid will be added _exit(1); } diff --git a/pdns/recursordist/pubsuffixloader.cc b/pdns/recursordist/pubsuffixloader.cc index ea8b9908d0..3d413d66c9 100644 --- a/pdns/recursordist/pubsuffixloader.cc +++ b/pdns/recursordist/pubsuffixloader.cc @@ -73,7 +73,7 @@ void initPublicSuffixList(const std::string& file) } catch (const std::exception& e) { SLOG(g_log << Logger::Warning << "Error while loading the Public Suffix List from '" << file << "', falling back to the built-in list: " << e.what() << endl, - g_slog->withName("runtime")->error(Logr::Error, e.what(), "Loaded the Public Suffix List", "file", Logging::Loggable(file))); + g_slog->withName("runtime")->error(Logr::Error, e.what(), "Error while loading the Public Suffix List", "file", Logging::Loggable(file))); } } diff --git a/pdns/recursordist/rec-lua-conf.cc b/pdns/recursordist/rec-lua-conf.cc index ec169e4544..96d1294170 100644 --- a/pdns/recursordist/rec-lua-conf.cc +++ b/pdns/recursordist/rec-lua-conf.cc @@ -377,13 +377,11 @@ static void rpzPrimary(LuaConfigItems& lci, luaConfigDelayedThreads& delayedThre } catch (const std::exception& e) { SLOG(g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.what() << endl, - lci.d_slog->error(Logr::Critical, e.what(), "Exception configuring 'rpzPrimary'", "exception", Logging::Loggable("std::exception"))); - exit(1); // FIXME proper exit code? + lci.d_slog->error(Logr::Error, e.what(), "Exception configuring 'rpzPrimary'", "exception", Logging::Loggable("std::exception"))); } catch (const PDNSException& e) { SLOG(g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.reason << endl, - lci.d_slog->error(Logr::Critical, e.reason, "Exception configuring 'rpzPrimary'", Logging::Loggable("PDNSException"))); - exit(1); // FIXME proper exit code? + lci.d_slog->error(Logr::Error, e.reason, "Exception configuring 'rpzPrimary'", Logging::Loggable("PDNSException"))); } delayedThreads.rpzPrimaryThreads.emplace_back(primaries, defpol, defpolOverrideLocal, maxTTL, zoneIdx, tt, maxReceivedXFRMBytes, localAddress, axfrTimeout, refresh, sr, dumpFile); diff --git a/pdns/recursordist/rec-taskqueue.cc b/pdns/recursordist/rec-taskqueue.cc index 9997991455..b5dba064df 100644 --- a/pdns/recursordist/rec-taskqueue.cc +++ b/pdns/recursordist/rec-taskqueue.cc @@ -134,23 +134,23 @@ static void resolveInternal(const struct timeval& now, bool logErrors, const pdn log->info(Logr::Debug, "done", "rcode", Logging::Loggable(res), "records", Logging::Loggable(ret.size())); } catch (const std::exception& e) { - log->error(Logr::Error, msg, e.what()); + log->error(Logr::Warning, msg, e.what()); } catch (const PDNSException& e) { - log->error(Logr::Error, msg, e.reason); + log->error(Logr::Warning, msg, e.reason); } catch (const ImmediateServFailException& e) { if (logErrors) { - log->error(Logr::Error, msg, e.reason); + log->error(Logr::Warning, msg, e.reason); } } catch (const PolicyHitException& e) { if (logErrors) { - log->error(Logr::Notice, msg, "PolicyHit"); + log->error(Logr::Warning, msg, "PolicyHit"); } } catch (...) { - log->error(Logr::Error, msg, "Unexpectec exception"); + log->error(Logr::Warning, msg, "Unexpectec exception"); } if (exceptionOccurred) { if (task.d_refreshMode) { @@ -195,14 +195,14 @@ static void tryDoT(const struct timeval& now, bool logErrors, const pdns::Resolv log->info(Logr::Debug, "done", "ok", Logging::Loggable(tryOK)); } catch (const std::exception& e) { - log->error(Logr::Error, msg, e.what()); + log->error(Logr::Warning, msg, e.what()); } catch (const PDNSException& e) { - log->error(Logr::Error, msg, e.reason); + log->error(Logr::Warning, msg, e.reason); } catch (const ImmediateServFailException& e) { if (logErrors) { - log->error(Logr::Error, msg, e.reason); + log->error(Logr::Warning, msg, e.reason); } } catch (const PolicyHitException& e) { @@ -211,7 +211,7 @@ static void tryDoT(const struct timeval& now, bool logErrors, const pdns::Resolv } } catch (...) { - log->error(Logr::Error, msg, "Unexpected exception"); + log->error(Logr::Warning, msg, "Unexpected exception"); } if (exceptionOccurred) { ++s_resolve_tasks.exceptions; diff --git a/pdns/recursordist/rec-tcp.cc b/pdns/recursordist/rec-tcp.cc index ca3c3b3e36..7d1a8bb3d1 100644 --- a/pdns/recursordist/rec-tcp.cc +++ b/pdns/recursordist/rec-tcp.cc @@ -1114,7 +1114,7 @@ void makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set& tcpSockets if (address.sin6.sin6_family == AF_INET6 && setsockopt(socketFd, IPPROTO_IPV6, IPV6_V6ONLY, &tmp, sizeof(tmp)) < 0) { int err = errno; SLOG(g_log << Logger::Error << "Failed to set IPv6 socket to IPv6 only, continuing anyhow: " << stringerror(err) << endl, - log->error(Logr::Error, err, "Failed to set IPv6 socket to IPv6 only, continuing anyhow")); + log->error(Logr::Warning, err, "Failed to set IPv6 socket to IPv6 only, continuing anyhow")); } #ifdef TCP_DEFER_ACCEPT diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 8e8819fb7c..253058ecac 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -5897,28 +5897,28 @@ int directResolve(const DNSName& qname, const QType qtype, const QClass qclass, res = sr.beginResolve(qname, qtype, qclass, ret, 0); } catch (const PDNSException& e) { - SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got pdns exception: " << e.reason << endl, - log->error(Logr::Error, e.reason, msg, "exception", Logging::Loggable("PDNSException"))); + SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got pdns exception: " << e.reason << endl, + log->error(Logr::Warning, e.reason, msg, "exception", Logging::Loggable("PDNSException"))); ret.clear(); } catch (const ImmediateServFailException& e) { - SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got ImmediateServFailException: " << e.reason << endl, - log->error(Logr::Error, e.reason, msg, "exception", Logging::Loggable("ImmediateServFailException"))); + SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got ImmediateServFailException: " << e.reason << endl, + log->error(Logr::Warning, e.reason, msg, "exception", Logging::Loggable("ImmediateServFailException"))); ret.clear(); } catch (const PolicyHitException& e) { - SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got a policy hit" << endl, - log->info(Logr::Error, msg, "exception", Logging::Loggable("PolicyHitException"))); + SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got a policy hit" << endl, + log->info(Logr::Warning, msg, "exception", Logging::Loggable("PolicyHitException"))); ret.clear(); } catch (const std::exception& e) { - SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got STL error: " << e.what() << endl, - log->error(Logr::Error, e.what(), msg, "exception", Logging::Loggable("std::exception"))); + SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got STL error: " << e.what() << endl, + log->error(Logr::Warning, e.what(), msg, "exception", Logging::Loggable("std::exception"))); ret.clear(); } catch (...) { - SLOG(g_log << Logger::Error << "Failed to resolve " << qname << ", got an exception" << endl, - log->info(Logr::Error, msg)); + SLOG(g_log << Logger::Warning << "Failed to resolve " << qname << ", got an exception" << endl, + log->info(Logr::Warning, msg)); ret.clear(); } diff --git a/pdns/unix_utility.cc b/pdns/unix_utility.cc index 2fb2d00e07..b6b169aa17 100644 --- a/pdns/unix_utility.cc +++ b/pdns/unix_utility.cc @@ -165,7 +165,7 @@ void Utility::dropGroupPrivs( uid_t uid, gid_t gid ) if (initgroups(pw->pw_name, gid)<0) { int err = errno; SLOG(g_log<withName("runtime")->error(Logr::Critical, err, "Unable to drop supplementary groups")); + g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to set supplementary groups")); exit(1); } } @@ -180,7 +180,7 @@ void Utility::dropUserPrivs( uid_t uid ) if(setuid(uid)<0) { int err = errno; SLOG(g_log<withName("runtime")->error(Logr::Error, err, "Unable to set effective user id", "uid", Logging::Loggable(uid))); + g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to set effective user id", "uid", Logging::Loggable(uid))); exit(1); } else {