Skip to content

Commit

Permalink
Logging: have a global g_log
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis committed Mar 23, 2018
1 parent c298c4d commit e715532
Show file tree
Hide file tree
Showing 108 changed files with 1,232 additions and 1,257 deletions.
68 changes: 34 additions & 34 deletions modules/bindbackend/bindbackend2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ void Bind2Backend::insertRecord(BB2DomainInfo& bb2, const DNSName &qname, const
else {
string msg = "Trying to insert non-zone data, name='"+bdr.qname.toLogString()+"', qtype="+qtype.getName()+", zone='"+bb2.d_name.toLogString()+"'";
if(s_ignore_broken_records) {
L<<Logger::Warning<<msg<< " ignored" << endl;
g_log<<Logger::Warning<<msg<< " ignored" << endl;
return;
}
else
Expand Down Expand Up @@ -604,7 +604,7 @@ string Bind2Backend::DLAddDomainHandler(const vector<string>&parts, Utility::pid

safePutBBDomainInfo(bbd);

L<<Logger::Warning<<"Zone "<<domainname<< " loaded"<<endl;
g_log<<Logger::Warning<<"Zone "<<domainname<< " loaded"<<endl;
return "Loaded zone " + domainname.toLogString() + " from " + filename;
}

Expand Down Expand Up @@ -737,7 +737,7 @@ void Bind2Backend::doEmptyNonTerminals(BB2DomainInfo& bbd, bool nsec3zone, NSEC3
{
if(!(maxent))
{
L<<Logger::Error<<"Zone '"<<bbd.d_name<<"' has too many empty non terminals."<<endl;
g_log<<Logger::Error<<"Zone '"<<bbd.d_name<<"' has too many empty non terminals."<<endl;
return;
}

Expand Down Expand Up @@ -776,7 +776,7 @@ void Bind2Backend::loadConfig(string* status)
BP.parse(getArg("config"));
}
catch(PDNSException &ae) {
L<<Logger::Error<<"Error parsing bind configuration: "<<ae.reason<<endl;
g_log<<Logger::Error<<"Error parsing bind configuration: "<<ae.reason<<endl;
throw;
}

Expand All @@ -786,7 +786,7 @@ void Bind2Backend::loadConfig(string* status)
s_binddirectory=BP.getDirectory();
// ZP.setDirectory(d_binddirectory);

L<<Logger::Warning<<d_logprefix<<" Parsing "<<domains.size()<<" domain(s), will report when done"<<endl;
g_log<<Logger::Warning<<d_logprefix<<" Parsing "<<domains.size()<<" domain(s), will report when done"<<endl;

set<DNSName> oldnames, newnames;
{
Expand Down Expand Up @@ -814,15 +814,15 @@ void Bind2Backend::loadConfig(string* status)
++i)
{
if (!(i->hadFileDirective)) {
L<<Logger::Warning<<d_logprefix<<" Zone '"<<i->name<<"' has no 'file' directive set in "<<getArg("config")<<endl;
g_log<<Logger::Warning<<d_logprefix<<" Zone '"<<i->name<<"' has no 'file' directive set in "<<getArg("config")<<endl;
rejected++;
continue;
}

if(i->type == "")
L<<Logger::Notice<<d_logprefix<<" Zone '"<<i->name<<"' has no type specified, assuming 'native'"<<endl;
g_log<<Logger::Notice<<d_logprefix<<" Zone '"<<i->name<<"' has no type specified, assuming 'native'"<<endl;
if(i->type!="master" && i->type!="slave" && i->type != "native" && i->type != "") {
L<<Logger::Warning<<d_logprefix<<" Warning! Skipping zone '"<<i->name<<"' because type '"<<i->type<<"' is invalid"<<endl;
g_log<<Logger::Warning<<d_logprefix<<" Warning! Skipping zone '"<<i->name<<"' because type '"<<i->type<<"' is invalid"<<endl;
rejected++;
continue;
}
Expand Down Expand Up @@ -853,7 +853,7 @@ void Bind2Backend::loadConfig(string* status)

newnames.insert(bbd.d_name);
if(filenameChanged || !bbd.d_loaded || !bbd.current()) {
L<<Logger::Info<<d_logprefix<<" parsing '"<<i->name<<"' from file '"<<i->filename<<"'"<<endl;
g_log<<Logger::Info<<d_logprefix<<" parsing '"<<i->name<<"' from file '"<<i->filename<<"'"<<endl;

try {
parseZoneFile(&bbd);
Expand All @@ -866,7 +866,7 @@ void Bind2Backend::loadConfig(string* status)
*status+=msg.str();
bbd.d_status=msg.str();

L<<Logger::Warning<<d_logprefix<<msg.str()<<endl;
g_log<<Logger::Warning<<d_logprefix<<msg.str()<<endl;
rejected++;
}
catch(std::system_error &ae) {
Expand All @@ -879,7 +879,7 @@ void Bind2Backend::loadConfig(string* status)
if(status)
*status+=msg.str();
bbd.d_status=msg.str();
L<<Logger::Warning<<d_logprefix<<msg.str()<<endl;
g_log<<Logger::Warning<<d_logprefix<<msg.str()<<endl;
rejected++;
}
catch(std::exception &ae) {
Expand All @@ -890,7 +890,7 @@ void Bind2Backend::loadConfig(string* status)
*status+=msg.str();
bbd.d_status=msg.str();

L<<Logger::Warning<<d_logprefix<<msg.str()<<endl;
g_log<<Logger::Warning<<d_logprefix<<msg.str()<<endl;
rejected++;
}
safePutBBDomainInfo(bbd);
Expand All @@ -916,7 +916,7 @@ void Bind2Backend::loadConfig(string* status)
if(status)
*status=msg.str();

L<<Logger::Error<<d_logprefix<<msg.str()<<endl;
g_log<<Logger::Error<<d_logprefix<<msg.str()<<endl;
}
}

Expand All @@ -931,20 +931,20 @@ void Bind2Backend::queueReloadAndStore(unsigned int id)
bbnew.d_checknow=false;
bbnew.d_wasRejectedLastReload=false;
safePutBBDomainInfo(bbnew);
L<<Logger::Warning<<"Zone '"<<bbnew.d_name<<"' ("<<bbnew.d_filename<<") reloaded"<<endl;
g_log<<Logger::Warning<<"Zone '"<<bbnew.d_name<<"' ("<<bbnew.d_filename<<") reloaded"<<endl;
}
catch(PDNSException &ae) {
ostringstream msg;
msg<<" error at "+nowTime()+" parsing '"<<bbold.d_name<<"' from file '"<<bbold.d_filename<<"': "<<ae.reason;
L<<Logger::Warning<<" error parsing '"<<bbold.d_name<<"' from file '"<<bbold.d_filename<<"': "<<ae.reason<<endl;
g_log<<Logger::Warning<<" error parsing '"<<bbold.d_name<<"' from file '"<<bbold.d_filename<<"': "<<ae.reason<<endl;
bbold.d_status=msg.str();
bbold.d_wasRejectedLastReload=true;
safePutBBDomainInfo(bbold);
}
catch(std::exception &ae) {
ostringstream msg;
msg<<" error at "+nowTime()+" parsing '"<<bbold.d_name<<"' from file '"<<bbold.d_filename<<"': "<<ae.what();
L<<Logger::Warning<<" error parsing '"<<bbold.d_name<<"' from file '"<<bbold.d_filename<<"': "<<ae.what()<<endl;
g_log<<Logger::Warning<<" error parsing '"<<bbold.d_name<<"' from file '"<<bbold.d_filename<<"': "<<ae.what()<<endl;
bbold.d_status=msg.str();
bbold.d_wasRejectedLastReload=true;
safePutBBDomainInfo(bbold);
Expand Down Expand Up @@ -1036,7 +1036,7 @@ void Bind2Backend::lookup(const QType &qtype, const DNSName &qname, DNSPacket *p

static bool mustlog=::arg().mustDo("query-logging");
if(mustlog)
L<<Logger::Warning<<"Lookup for '"<<qtype.getName()<<"' of '"<<domain<<"' within zoneID "<<zoneId<<endl;
g_log<<Logger::Warning<<"Lookup for '"<<qtype.getName()<<"' of '"<<domain<<"' within zoneID "<<zoneId<<endl;
bool found=false;
BB2DomainInfo bbd;

Expand All @@ -1046,17 +1046,17 @@ void Bind2Backend::lookup(const QType &qtype, const DNSName &qname, DNSPacket *p

if(!found) {
if(mustlog)
L<<Logger::Warning<<"Found no authoritative zone for "<<qname<<endl;
g_log<<Logger::Warning<<"Found no authoritative zone for "<<qname<<endl;
d_handle.d_list=false;
return;
}

if(mustlog)
L<<Logger::Warning<<"Found a zone '"<<domain<<"' (with id " << bbd.d_id<<") that might contain data "<<endl;
g_log<<Logger::Warning<<"Found a zone '"<<domain<<"' (with id " << bbd.d_id<<") that might contain data "<<endl;

d_handle.id=bbd.d_id;

DLOG(L<<"Bind2Backend constructing handle for search for "<<qtype.getName()<<" for "<<
DLOG(g_log<<"Bind2Backend constructing handle for search for "<<qtype.getName()<<" for "<<
qname<<endl);

if(domain.empty())
Expand All @@ -1073,7 +1073,7 @@ void Bind2Backend::lookup(const QType &qtype, const DNSName &qname, DNSPacket *p
}

if(!bbd.current()) {
L<<Logger::Warning<<"Zone '"<<bbd.d_name<<"' ("<<bbd.d_filename<<") needs reloading"<<endl;
g_log<<Logger::Warning<<"Zone '"<<bbd.d_name<<"' ("<<bbd.d_filename<<") needs reloading"<<endl;
queueReloadAndStore(bbd.d_id);
if (!safeGetBBDomainInfo(domain, &bbd))
throw DBException("Zone '"+bbd.d_name.toLogString()+"' ("+bbd.d_filename+") gone after reload"); // if we don't throw here, we crash for some reason
Expand All @@ -1082,7 +1082,7 @@ void Bind2Backend::lookup(const QType &qtype, const DNSName &qname, DNSPacket *p
d_handle.d_records = bbd.d_records.get();

if(d_handle.d_records->empty())
DLOG(L<<"Query with no results"<<endl);
DLOG(g_log<<"Query with no results"<<endl);

d_handle.mustlog = mustlog;

Expand Down Expand Up @@ -1111,20 +1111,20 @@ bool Bind2Backend::get(DNSResourceRecord &r)
{
if(!d_handle.d_records) {
if(d_handle.mustlog)
L<<Logger::Warning<<"There were no answers"<<endl;
g_log<<Logger::Warning<<"There were no answers"<<endl;
return false;
}

if(!d_handle.get(r)) {
if(d_handle.mustlog)
L<<Logger::Warning<<"End of answers"<<endl;
g_log<<Logger::Warning<<"End of answers"<<endl;

d_handle.reset();

return false;
}
if(d_handle.mustlog)
L<<Logger::Warning<<"Returning: '"<<r.qtype.getName()<<"' of '"<<r.qname<<"', content: '"<<r.content<<"'"<<endl;
g_log<<Logger::Warning<<"Returning: '"<<r.qtype.getName()<<"' of '"<<r.qname<<"', content: '"<<r.content<<"'"<<endl;
return true;
}

Expand All @@ -1146,21 +1146,21 @@ void Bind2Backend::handle::reset()
//#define DLOG(x) x
bool Bind2Backend::handle::get_normal(DNSResourceRecord &r)
{
DLOG(L << "Bind2Backend get() was called for "<<qtype.getName() << " record for '"<<
DLOG(g_log << "Bind2Backend get() was called for "<<qtype.getName() << " record for '"<<
qname<<"' - "<<d_records->size()<<" available in total!"<<endl);

if(d_iter==d_end_iter) {
return false;
}

while(d_iter!=d_end_iter && !(qtype.getCode()==QType::ANY || (d_iter)->qtype==qtype.getCode())) {
DLOG(L<<Logger::Warning<<"Skipped "<<qname<<"/"<<QType(d_iter->qtype).getName()<<": '"<<d_iter->content<<"'"<<endl);
DLOG(g_log<<Logger::Warning<<"Skipped "<<qname<<"/"<<QType(d_iter->qtype).getName()<<": '"<<d_iter->content<<"'"<<endl);
d_iter++;
}
if(d_iter==d_end_iter) {
return false;
}
DLOG(L << "Bind2Backend get() returning a rr with a "<<QType(d_iter->qtype).getCode()<<endl);
DLOG(g_log << "Bind2Backend get() returning a rr with a "<<QType(d_iter->qtype).getCode()<<endl);

r.qname=qname.empty() ? domain : (qname+domain);
r.domain_id=id;
Expand All @@ -1186,7 +1186,7 @@ bool Bind2Backend::list(const DNSName& target, int id, bool include_disabled)
return false;

d_handle.reset();
DLOG(L<<"Bind2Backend constructing handle for list of "<<id<<endl);
DLOG(g_log<<"Bind2Backend constructing handle for list of "<<id<<endl);

d_handle.d_records=bbd.d_records.get(); // give it a copy, which will stay around
d_handle.d_qname_iter= d_handle.d_records->begin();
Expand Down Expand Up @@ -1237,7 +1237,7 @@ bool Bind2Backend::superMasterBackend(const string &ip, const DNSName& domain, c

ifstream c_if(getArg("supermasters").c_str(), std::ios::in); // this was nocreate?
if (!c_if) {
L << Logger::Error << "Unable to open supermasters file for read: " << stringerror() << endl;
g_log << Logger::Error << "Unable to open supermasters file for read: " << stringerror() << endl;
return false;
}

Expand Down Expand Up @@ -1288,7 +1288,7 @@ bool Bind2Backend::createSlaveDomain(const string &ip, const DNSName& domain, co
{
string filename = getArg("supermaster-destdir")+'/'+domain.toStringNoDot();

L << Logger::Warning << d_logprefix
g_log << Logger::Warning << d_logprefix
<< " Writing bind config zone statement for superslave zone '" << domain
<< "' from supermaster " << ip << endl;

Expand All @@ -1297,7 +1297,7 @@ bool Bind2Backend::createSlaveDomain(const string &ip, const DNSName& domain, co

ofstream c_of(getArg("supermaster-config").c_str(), std::ios::app);
if (!c_of) {
L << Logger::Error << "Unable to open supermaster configfile for append: " << stringerror() << endl;
g_log << Logger::Error << "Unable to open supermaster configfile for append: " << stringerror() << endl;
throw DBException("Unable to open supermaster configfile for append: "+stringerror());
}

Expand All @@ -1323,7 +1323,7 @@ bool Bind2Backend::searchRecords(const string &pattern, int maxResults, vector<D
SimpleMatch sm(pattern,true);
static bool mustlog=::arg().mustDo("query-logging");
if(mustlog)
L<<Logger::Warning<<"Search for pattern '"<<pattern<<"'"<<endl;
g_log<<Logger::Warning<<"Search for pattern '"<<pattern<<"'"<<endl;

{
ReadLock rl(&s_state_lock);
Expand Down Expand Up @@ -1387,7 +1387,7 @@ class Bind2Loader
Bind2Loader()
{
BackendMakers().report(new Bind2Factory);
L << Logger::Info << "[bind2backend] This is the bind backend version " << VERSION
g_log << Logger::Info << "[bind2backend] This is the bind backend version " << VERSION
#ifndef REPRODUCIBLE
<< " (" __DATE__ " " __TIME__ ")"
#endif
Expand Down
4 changes: 2 additions & 2 deletions modules/bindbackend/binddnssec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ bool Bind2Backend::getNSEC3PARAM(const DNSName& name, NSEC3PARAMRecordContent* n

if (ns3p->d_iterations > maxNSEC3Iterations) {
ns3p->d_iterations = maxNSEC3Iterations;
L<<Logger::Error<<"Number of NSEC3 iterations for zone '"<<name<<"' is above 'max-nsec3-iterations'. Value adjusted to: "<<maxNSEC3Iterations<<endl;
g_log<<Logger::Error<<"Number of NSEC3 iterations for zone '"<<name<<"' is above 'max-nsec3-iterations'. Value adjusted to: "<<maxNSEC3Iterations<<endl;
}

if (ns3p->d_algorithm != 1) {
L<<Logger::Error<<"Invalid hash algorithm for NSEC3: '"<<std::to_string(ns3p->d_algorithm)<<"', setting to 1 for zone '"<<name<<"'."<<endl;
g_log<<Logger::Error<<"Invalid hash algorithm for NSEC3: '"<<std::to_string(ns3p->d_algorithm)<<"', setting to 1 for zone '"<<name<<"'."<<endl;
ns3p->d_algorithm = 1;
}
}
Expand Down
16 changes: 8 additions & 8 deletions modules/geoipbackend/geoipbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void GeoIPBackend::initialize() {
}

if (s_geoip_files.empty())
L<<Logger::Warning<<"No GeoIP database files loaded!"<<endl;
g_log<<Logger::Warning<<"No GeoIP database files loaded!"<<endl;

config = YAML::LoadFile(getArg("zones-file"));

Expand Down Expand Up @@ -138,14 +138,14 @@ void GeoIPBackend::initialize() {
} else if (attr == "weight") {
rr.weight = iter->second.as<int>();
if (rr.weight < 0) {
L<<Logger::Error<<"Weight cannot be negative for " << rr.qname << endl;
g_log<<Logger::Error<<"Weight cannot be negative for " << rr.qname << endl;
throw PDNSException(string("Weight cannot be negative for ") + rr.qname.toLogString());
}
rr.has_weight = true;
} else if (attr == "ttl") {
rr.ttl = iter->second.as<int>();
} else {
L<<Logger::Error<<"Unsupported record attribute " << attr << " for " << rr.qname << endl;
g_log<<Logger::Error<<"Unsupported record attribute " << attr << " for " << rr.qname << endl;
throw PDNSException(string("Unsupported record attribute ") + attr + string(" for ") + rr.qname.toLogString());
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ void GeoIPBackend::lookup(const QType &qtype, const DNSName& qdomain, DNSPacket
}

if (!d_result.empty()) {
L<<Logger::Error<<
g_log<<Logger::Error<<
"Cannot have static record and CNAME at the same time." <<
"Please fix your configuration for \"" << qdomain << "\", so that " <<
"it can be resolved by GeoIP backend directly."<< std::endl;
Expand Down Expand Up @@ -590,11 +590,11 @@ void GeoIPBackend::reload() {
try {
initialize();
} catch (PDNSException &pex) {
L<<Logger::Error<<"GeoIP backend reload failed: " << pex.reason << endl;
g_log<<Logger::Error<<"GeoIP backend reload failed: " << pex.reason << endl;
} catch (std::exception &stex) {
L<<Logger::Error<<"GeoIP backend reload failed: " << stex.what() << endl;
g_log<<Logger::Error<<"GeoIP backend reload failed: " << stex.what() << endl;
} catch (...) {
L<<Logger::Error<<"GeoIP backend reload failed" << endl;
g_log<<Logger::Error<<"GeoIP backend reload failed" << endl;
}
}

Expand Down Expand Up @@ -861,7 +861,7 @@ class GeoIPLoader {
public:
GeoIPLoader() {
BackendMakers().report(new GeoIPFactory);
L << Logger::Info << "[geoipbackend] This is the geoip backend version " VERSION
g_log << Logger::Info << "[geoipbackend] This is the geoip backend version " VERSION
#ifndef REPRODUCIBLE
<< " (" __DATE__ " " __TIME__ ")"
#endif
Expand Down
6 changes: 3 additions & 3 deletions modules/geoipbackend/geoipinterface-mmdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GeoIPInterfaceMMDB : public GeoIPInterface {
if ((ec = MMDB_open(fname.c_str(), flags, &d_s)) < 0)
throw PDNSException(string("Cannot open ") + fname + string(": ") + string(MMDB_strerror(ec)));
d_lang = language;
L<<Logger::Debug<<"Opened MMDB database "<<fname<<"(type: "<<d_s.metadata.database_type<<
g_log<<Logger::Debug<<"Opened MMDB database "<<fname<<"(type: "<<d_s.metadata.database_type<<
" version: "<<d_s.metadata.binary_format_major_version << "." <<
d_s.metadata.binary_format_minor_version << ")" << endl;
}
Expand Down Expand Up @@ -242,9 +242,9 @@ class GeoIPInterfaceMMDB : public GeoIPInterface {
res = MMDB_lookup_string(&d_s, ip.c_str(), &gai_ec, &mmdb_ec);

if (gai_ec != 0)
L<<Logger::Warning<<"MMDB_lookup_string("<<ip<<") failed: "<<gai_strerror(gai_ec)<<endl;
g_log<<Logger::Warning<<"MMDB_lookup_string("<<ip<<") failed: "<<gai_strerror(gai_ec)<<endl;
else if (mmdb_ec != MMDB_SUCCESS)
L<<Logger::Warning<<"MMDB_lookup_string("<<ip<<") failed: "<<MMDB_strerror(mmdb_ec)<<endl;
g_log<<Logger::Warning<<"MMDB_lookup_string("<<ip<<") failed: "<<MMDB_strerror(mmdb_ec)<<endl;
else if (res.found_entry) {
gl.netmask = res.netmask;
/* If it's a IPv6 database, IPv4 netmasks are reduced from 128, so we need to deduct
Expand Down
6 changes: 3 additions & 3 deletions modules/gmysqlbackend/gmysqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ gMySQLBackend::gMySQLBackend(const string &mode, const string &suffix) : GSQLBa
}

catch(SSqlException &e) {
L<<Logger::Error<<mode<<" Connection failed: "<<e.txtReason()<<endl;
g_log<<Logger::Error<<mode<<" Connection failed: "<<e.txtReason()<<endl;
throw PDNSException("Unable to launch "+mode+" connection: "+e.txtReason());
}
L<<Logger::Info<<mode<<" Connection successful. Connected to database '"<<getArg("dbname")<<"' on '"<<(getArg("host").empty() ? getArg("socket") : getArg("host"))<<"'."<<endl;
g_log<<Logger::Info<<mode<<" Connection successful. Connected to database '"<<getArg("dbname")<<"' on '"<<(getArg("host").empty() ? getArg("socket") : getArg("host"))<<"'."<<endl;
}

void gMySQLBackend::reconnect()
Expand Down Expand Up @@ -173,7 +173,7 @@ class gMySQLLoader
gMySQLLoader()
{
BackendMakers().report(new gMySQLFactory("gmysql"));
L << Logger::Info << "[gmysqlbackend] This is the gmysql backend version " VERSION
g_log << Logger::Info << "[gmysqlbackend] This is the gmysql backend version " VERSION
#ifndef REPRODUCIBLE
<< " (" __DATE__ " " __TIME__ ")"
#endif
Expand Down
Loading

0 comments on commit e715532

Please sign in to comment.