[Resolver-log] Replacing unused debuging functions by LOG(x).
Removing printf/vlog/syslog/ ...etc debuging functions and using LOG(x).
Then we can configure the log verbosity in the resolver with:
// Set the minimum severity level for logging, returning the old severity.
LogSeverity SetMinimumLogSeverity(LogSeverity new_severity);
Bug: 121176138
Test: make; flash;
Test: The default severity is WARNING. Reboot device and check that only
WARNING/ERROR logs are printed.
Change-Id: Ib8de89a4cba96ded186579ccefaf88031066e508
diff --git a/resolv/res_query.cpp b/resolv/res_query.cpp
index acf6160..f5da81f 100644
--- a/resolv/res_query.cpp
+++ b/resolv/res_query.cpp
@@ -83,14 +83,11 @@
#include <string.h>
#include <unistd.h>
+#include <android-base/logging.h>
+
#include "resolv_cache.h"
#include "resolv_private.h"
-/* Options. Leave them on. */
-#ifndef DEBUG
-#define DEBUG
-#endif
-
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
@@ -123,17 +120,13 @@
again:
hp->rcode = NOERROR; /* default */
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_query(%s, %d, %d)\n", name, cl, type);
-#endif
+ LOG(DEBUG) << ";; res_query(" << name << ", " << cl << ", " << type;
n = res_nmkquery(statp, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
if (n > 0 && (statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U && !retried)
n = res_nopt(statp, n, buf, sizeof(buf), anslen);
if (n <= 0) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_query: mkquery failed\n");
-#endif
+ LOG(DEBUG) << ";; res_query: mkquery failed";
*herrno = NO_RECOVERY;
return n;
}
@@ -142,13 +135,12 @@
/* if the query choked with EDNS0, retry without EDNS0 */
if ((statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U &&
(statp->_flags & RES_F_EDNS0ERR) && !retried) {
- if (statp->options & RES_DEBUG) printf(";; res_nquery: retry without EDNS0\n");
+ LOG(DEBUG) << ";; res_nquery: retry without EDNS0";
retried = true;
goto again;
}
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_query: send error\n");
-#endif
+ LOG(DEBUG) << ";; res_query: send error";
+
// Note that rcodes SERVFAIL, NOTIMP, REFUSED may cause res_nquery() to return a general
// error code EAI_AGAIN, but mapping the error code from rcode as res_queryN() does for
// getaddrinfo(). Different rcodes trigger different behaviors:
@@ -175,11 +167,10 @@
}
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n", p_rcode(hp->rcode),
- ntohs(hp->ancount), ntohs(hp->nscount), ntohs(hp->arcount));
-#endif
+ LOG(DEBUG) << ";; rcode = (" << p_rcode(hp->rcode)
+ << "), counts = an:" << ntohs(hp->ancount) << " ns:" << ntohs(hp->nscount)
+ << " ar:" << ntohs(hp->arcount);
+
switch (hp->rcode) {
case NXDOMAIN:
*herrno = HOST_NOT_FOUND;
@@ -356,12 +347,8 @@
const char* longname = nbuf;
int n, d;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_nquerydomain(%s, %s, %d, %d)\n", name, domain ? domain : "<Nil>", cl,
- type);
-#endif
if (domain == NULL) {
+ LOG(DEBUG) << ";; res_nquerydomain(" << name << ", <Nil>, " << cl << ", " << type << ")";
/*
* Check for trailing '.';
* copy without '.' if present.
@@ -378,6 +365,8 @@
} else
longname = name;
} else {
+ LOG(DEBUG) << ";; res_nquerydomain(" << name << ", " << domain << ", " << cl << ", " << type
+ << ")";
n = strlen(name);
d = strlen(domain);
if (n + d + 1 >= MAXDNAME) {