#include <unordered_map>
#include <typeinfo>
#include "logger.hh"
+#include "logging.hh"
#include "iputils.hh"
#include "dnsname.hh"
#include "dnsparser.hh"
std::ifstream ifs(fname);
if (!ifs) {
ret = errno;
- g_log<<Logger::Error<<"Unable to read configuration file from '"<<fname<<"': "<<stringerror()<<endl;
+ SLOG(g_log<<Logger::Error<<"Unable to read configuration file from '"<<fname<<"': "<<stringerror(ret)<<endl,
+ g_slog->withName("lua")->error(Logr::Error, ret, "Unable to read configuration file", "file", Logging::Loggable(fname)));
return ret;
}
loadStream(ifs);
else
cas.insert(boost::get<ComboAddress>(in));
}
- catch(std::exception& e) { g_log <<Logger::Error<<e.what()<<endl; }
+ catch(std::exception& e) {
+ SLOG(g_log <<Logger::Error<<e.what()<<endl,
+ g_slog->withName("lua")->error(Logr::Error, e.what(), "Exception in newCAS", "exception", Logging::Loggable("std::exception")));
+ }
});
d_lw->registerFunction<bool(cas_t::*)(const ComboAddress&)>("check",[](const cas_t& cas, const ComboAddress&ca) { return cas.count(ca)>0; });
d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); });
// pdnsload
- d_lw->writeFunction("pdnslog", [](const std::string& msg, boost::optional<int> loglevel) { g_log << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<<endl; });
+ d_lw->writeFunction("pdnslog", [](const std::string& msg, boost::optional<int> loglevel) {
+ SLOG(g_log << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<<endl,
+ g_slog->withName("lua")->info(static_cast<Logr::Priority>(loglevel.get_value_or(Logr::Warning)), msg));
+ });
d_lw->writeFunction("pdnsrandom", [](boost::optional<uint32_t> maximum) { return dns_random(maximum.get_value_or(0xffffffff)); });
// certain constants
#include "threadname.hh"
#include <stdlib.h>
#include "logger.hh"
+#include "logging.hh"
#include "misc.hh"
using namespace nod;
if (d_init)
return false;
+ auto log = g_slog->withName("nod");
std::lock_guard<std::mutex> lock(d_cachedir_mutex);
if (d_cachedir.length()) {
filesystem::path p(d_cachedir);
std::ifstream infile;
try {
infile.open(filename, std::ios::in | std::ios::binary);
- g_log << Logger::Warning << "Found SBF file " << filename << endl;
+ SLOG(g_log << Logger::Warning << "Found SBF file " << filename << endl,
+ log->info(Logr::Warning, "Found SBF File", "file", Logging::Loggable(filename)));
// read the file into the sbf
d_sbf.lock()->restore(infile);
infile.close();
catch (const std::runtime_error& e) {
infile.close();
filesystem::remove(newest_file);
- g_log<<Logger::Warning<<"NODDB init: Cannot parse file: " << filename << ": " << e.what() << "; removed" << endl;
+ SLOG(g_log<<Logger::Warning<<"NODDB init: Cannot parse file: " << filename << ": " << e.what() << "; removed" << endl,
+ log->error(Logr::Warning, e.what(), "NODDB init: Cannot parse file, removed", "file", Logging::Loggable(filename)));
}
}
}
}
catch (const filesystem::filesystem_error& e) {
- g_log<<Logger::Warning<<"NODDB init failed:: " << e.what() << endl;
+ SLOG(g_log<<Logger::Warning<<"NODDB init failed:: " << e.what() << endl,
+ log->error(Logr::Warning, e.what(), "NODDB init failed", "exception", Logging::Loggable("filesystem::filesystem_error")));
return false;
}
}
// file IO to complete
bool PersistentSBF::snapshotCurrent(std::thread::id tid)
{
+ auto log = g_slog->withName("nod");
if (d_cachedir.length()) {
filesystem::path p(d_cachedir);
filesystem::path f(d_cachedir);
filesystem::rename(ftmp, f);
}
catch (const std::runtime_error& e) {
- g_log<<Logger::Warning<<"NODDB snapshot: Cannot rename file: " << e.what() << endl;
+ SLOG(g_log<<Logger::Warning<<"NODDB snapshot: Cannot rename file: " << e.what() << endl,
+ log->error(Logr::Warning, e.what(), "NODDB snapshot: Cannot rename file", "exception", Logging::Loggable("std::runtime_error")));
filesystem::remove(ftmp);
throw;
}
return true;
}
catch (const std::runtime_error& e) {
- g_log<<Logger::Warning<<"NODDB snapshot: Cannot write file: " << e.what() << endl;
+ SLOG(g_log<<Logger::Warning<<"NODDB snapshot: Cannot write file: " << e.what() << endl,
+ log->error(Logr::Warning, e.what(), "NODDB snapshot: Cannot write file", "exception", Logging::Loggable("std::runtime_error")));
}
}
else {
- g_log<<Logger::Warning<<"NODDB snapshot: Cannot write file: " << f.string() << endl;
+ SLOG(g_log<<Logger::Warning<<"NODDB snapshot: Cannot write file: " << f.string() << endl,
+ log->info(Logr::Warning, "NODDB snapshot: Cannot write file", "file", Logging::Loggable(f.string())));
}
}
return false;
#include "rec_channel.hh"
#include "iputils.hh"
#include "logger.hh"
+#include "logging.hh"
#include "arguments.hh"
#include "lock.hh"
void doCarbonDump(void*)
{
+ auto log = g_slog->withName("carbon");
try {
static thread_local auto configHolder = g_carbonConfig.getLocal();
auto ret = asendtcp(msg, handler); // this will actually do the right thing waiting on the connect
if (ret == LWResult::Result::Timeout) {
- g_log << Logger::Warning << "Timeout connecting/writing carbon data to " << remote.toStringWithPort() << endl;
+ SLOG(g_log << Logger::Warning << "Timeout connecting/writing carbon data to " << remote.toStringWithPort() << endl,
+ log->info(Logr::Warning, "Timeout connecting/writing carbon data", "address", Logging::Loggable(remote)));
}
else if (ret != LWResult::Result::Success) {
- g_log << Logger::Warning << "Error writing carbon data to " << remote.toStringWithPort() << ": " << stringerror() << endl;
+ int err = errno;
+ SLOG(g_log << Logger::Warning << "Error writing carbon data to " << remote.toStringWithPort() << ": " << stringerror(err) << endl,
+ log->error(Logr::Warning, err, "Error writing carbon data", "address", Logging::Loggable(remote)));
}
handler->close();
}
}
catch (const PDNSException& e) {
- g_log << Logger::Error << "Error in carbon thread: " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Error in carbon thread: " << e.reason << endl,
+ log->error(Logr::Error, e.reason, "Error in carbon thread", "exception", Logging::Loggable("PDNSException")));
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Error in carbon thread: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Error in carbon thread: " << e.what() << endl,
+ log->error(Logr::Error, e.what(), "Error in carbon thread", "exception", Logging::Loggable("std::exception")));
}
catch (...) {
- g_log << Logger::Error << "Unknown error in carbon thread" << endl;
+ SLOG(g_log << Logger::Error << "Unknown error in carbon thread" << endl,
+ log->info(Logr::Error, "Error in carbon thread"));
}
}
#include "rec_channel.hh"
#include "logger.hh"
+#include "logging.hh"
#ifdef HAVE_NET_SNMP
static void registerCounter64Stat(const std::string& name, const oid statOID[], size_t statOIDLength)
{
if (statOIDLength != OID_LENGTH(questionsOID)) {
- g_log << Logger::Error << "Invalid OID for SNMP Counter64 statistic " << name << endl;
+ SLOG(g_log << Logger::Error << "Invalid OID for SNMP Counter64 statistic " << name << endl,
+ g_slog->withName("snmp")->info(Logr::Error, "Invalid OID for SNMP Counter64 statistic", "name", Logging::Loggable(name)));
return;
}
if (s_statsMap.find(statOID[statOIDLength - 1]) != s_statsMap.end()) {
- g_log << Logger::Error << "OID for SNMP Counter64 statistic " << name << " has already been registered" << endl;
+ SLOG(g_log << Logger::Error << "OID for SNMP Counter64 statistic " << name << " has already been registered" << endl,
+ g_slog->withName("snmp")->info(Logr::Error, "OID for SNMP Counter64 statistic has already been registered", "name", Logging::Loggable(name)));
return;
}
#include "dnsname.hh"
#include "logger.hh"
+#include "logging.hh"
#include "misc.hh"
#include "pubsuffix.hh"
}
}
- g_log << Logger::Info << "Loaded the Public Suffix List from '" << file << "'" << endl;
+ SLOG(g_log << Logger::Info << "Loaded the Public Suffix List from '" << file << "'" << endl,
+ g_slog->withName("runtime")->info(Logr::Info, "Loaded the Public Suffix List", "file", Logging::Loggable(file)));
loaded = true;
}
catch (const std::exception& e) {
- g_log << Logger::Warning << "Error while loading the Public Suffix List from '" << file << "', falling back to the built-in list: " << e.what() << endl;
+ 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)));
}
}
auto soa = getRR<SOARecordContent>(dr);
auto serial = soa ? soa->d_st.serial : 0;
SLOG(g_log<<Logger::Info<<"Getting IXFR deltas for "<<zoneName<<" from "<<primary.toStringWithPort()<<", our serial: "<<serial<<endl,
- logger->info(Logr::Info, "Getting IXFR deltas", "address", Logging::Loggable(primary)));
+ logger->info(Logr::Info, "Getting IXFR deltas", "address", Logging::Loggable(primary), "ourserial", Logging::Loggable(serial)));
ComboAddress local(localAddress);
if (local == ComboAddress()) {
bool SyncRes::tryDoT(const DNSName& qname, const QType qtype, const DNSName& nsName, ComboAddress address, time_t now)
{
- auto logHelper = [](const string& msg) {
- g_log<<Logger::Debug<<"Failed to probe DoT records, got an exception: "<<msg<<endl;
+ auto log = g_slog->withName("taskq")->withValues("method", Logging::Loggable("tryDoT"), "name", Logging::Loggable(qname), "qtype", Logging::Loggable(QType(qtype).toString()), "ip", Logging::Loggable(address));
+
+ auto logHelper1 = [&log](const string& ename) {
+ log->info(Logr::Debug, "Failed to probe DoT records, got an exception", "exception", Logging::Loggable(ename));
+ };
+ auto logHelper2 = [&log](const string& msg, const string& ename) {
+ log->error(Logr::Debug, msg, "Failed to probe DoT records, got an exception", "exception", Logging::Loggable(ename));
};
LWResult lwr;
bool truncated;
ok = ok && lwr.d_rcode == RCode::NoError && lwr.d_records.size() > 0;
}
catch(const PDNSException& e) {
- logHelper(e.reason);
+ logHelper2(e.reason, "PDNSException");
}
catch(const ImmediateServFailException& e) {
- logHelper(e.reason);
+ logHelper2(e.reason, "ImmediateServFailException");
}
catch(const PolicyHitException& e) {
- logHelper("PolicyHitException");
+ logHelper1("PolicyHitException");
}
catch(const std::exception& e) {
- logHelper(e.what());
+ logHelper2(e.what(), "std::exception");
}
catch(...) {
- logHelper("other");
+ logHelper1("other");
}
updateDoTStatus(address, ok ? DoTStatus::Good : DoTStatus::Bad, now + (ok ? dotSuccessWait : dotFailWait), true);
return ok;
#include "dolog.hh"
#else
#include "logger.hh"
+#include "logging.hh"
#endif
#include "threadname.hh"
#ifdef DNSDIST
warnlog("Could not set thread name %s for thread: %s", threadName, strerror(retval));
#else
- g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for thread: "<<strerror(retval)<<endl;
+ SLOG(g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for thread: "<<strerror(retval)<<endl,
+ g_slog->withName("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName)));
#endif
}
}
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
-#include <stdlib.h>
+#include <stdlib.h>
#include "pdnsexception.hh"
#include "logger.hh"
+#include "logging.hh"
#include "misc.hh"
#include <pwd.h>
#include <grp.h>
(void) one; // avoids 'unused var' warning on systems that have none of the defines checked below
#ifdef IP_FREEBIND
- if (setsockopt(sock, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0)
- g_log<<Logger::Warning<<"Warning: IP_FREEBIND setsockopt failed: "<<stringerror()<<endl;
+ if (setsockopt(sock, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0) {
+ int err = errno;
+ SLOG(g_log<<Logger::Warning<<"Warning: IP_FREEBIND setsockopt failed: "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Warning, err, "Warning: IP_FREEBIND setsockopt failed"));
+ }
#endif
#ifdef IP_BINDANY
if (af == AF_INET)
- if (setsockopt(sock, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) < 0)
- g_log<<Logger::Warning<<"Warning: IP_BINDANY setsockopt failed: "<<stringerror()<<endl;
+ if (setsockopt(sock, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) < 0) {
+ int err = errno;
+ SLOG(g_log<<Logger::Warning<<"Warning: IP_BINDANY setsockopt failed: "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Warning, err, "Warning: IP_BINDANY setsockopt failed"));
+ }
#endif
#ifdef IPV6_BINDANY
- if (af == AF_INET6)
- if (setsockopt(sock, IPPROTO_IPV6, IPV6_BINDANY, &one, sizeof(one)) < 0)
- g_log<<Logger::Warning<<"Warning: IPV6_BINDANY setsockopt failed: "<<stringerror()<<endl;
+ if (af == AF_INET6) {
+ if (setsockopt(sock, IPPROTO_IPV6, IPV6_BINDANY, &one, sizeof(one)) < 0) {
+ SLOG(g_log<<Logger::Warning<<"Warning: IPV6_BINDANY setsockopt failed: "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Warning, err, ""Warning: IPV6_BINDANY setsockopt failed"));
+ }
+ }
#endif
#ifdef SO_BINDANY
- if (setsockopt(sock, SOL_SOCKET, SO_BINDANY, &one, sizeof(one)) < 0)
- g_log<<Logger::Warning<<"Warning: SO_BINDANY setsockopt failed: "<<stringerror()<<endl;
+ if (setsockopt(sock, SOL_SOCKET, SO_BINDANY, &one, sizeof(one)) < 0) {
+ int err = errno;
+ SLOG(g_log<<Logger::Warning<<"Warning: SO_BINDANY setsockopt failed: "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Warning, err, "Warning: SO_BINDANY setsockopt failed"));
+ }
#endif
}
{
if(gid && gid != getegid()) {
if(setgid(gid)<0) {
- g_log<<Logger::Critical<<"Unable to set effective group id to "<<gid<<": "<<stringerror()<<endl;
+ int err = errno;
+ SLOG(g_log<<Logger::Critical<<"Unable to set effective group id to "<<gid<<": "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to set effective group id", "gid", Logging::Loggable(gid)));
exit(1);
}
- else
- g_log<<Logger::Info<<"Set effective group id to "<<gid<<endl;
-
+ else {
+ SLOG(g_log<<Logger::Info<<"Set effective group id to "<<gid<<endl,
+ g_slog->withName("runtime")->info(Logr::Info, "Set effective group id", "gid", Logging::Loggable(gid)));
+ }
struct passwd *pw=getpwuid(uid);
if(!pw) {
- g_log<<Logger::Warning<<"Unable to determine user name for uid "<<uid<<endl;
+ SLOG(g_log<<Logger::Warning<<"Unable to determine user name for uid "<<uid<<endl,
+ g_slog->withName("runtime")->info(Logr::Warning, "Unable to determine user name", "uid", Logging::Loggable(uid)));
if (setgroups(0, nullptr)<0) {
- g_log<<Logger::Critical<<"Unable to drop supplementary gids: "<<stringerror()<<endl;
+ int err = errno;
+ SLOG(g_log<<Logger::Critical<<"Unable to drop supplementary gids: "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to drop supplementary gids"));
exit(1);
}
} else {
if (initgroups(pw->pw_name, gid)<0) {
- g_log<<Logger::Critical<<"Unable to set supplementary groups: "<<stringerror()<<endl;
+ int err = errno;
+ SLOG(g_log<<Logger::Critical<<"Unable to set supplementary groups: "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Critical, err, "Unable to drop supplementary groups"));
exit(1);
}
}
{
if(uid && uid != geteuid()) {
if(setuid(uid)<0) {
- g_log<<Logger::Critical<<"Unable to set effective user id to "<<uid<<": "<<stringerror()<<endl;
+ int err = errno;
+ SLOG(g_log<<Logger::Critical<<"Unable to set effective user id to "<<uid<<": "<<stringerror(err)<<endl,
+ g_slog->withName("runtime")->error(Logr::Error, err, "Unable to set effective user id", "uid", Logging::Loggable(uid)));
exit(1);
}
- else
- g_log<<Logger::Info<<"Set effective user id to "<<uid<<endl;
+ else {
+ SLOG(g_log<<Logger::Info<<"Set effective user id to "<<uid<<endl,
+ g_slog->withName("runtime")->info("Set effective user", "uid", Logging::Loggable(uid)));
+ }
}
}