Disable sensitive logs

- PII logs can only appear in VERBOSE level
- logSeverityStrToEnum() no more support VERBOSE level input, only
accept DEBUG, INFO, WARNING, and ERROR.
- developer can set DBG flag from code to have a debug build, the DEBUG
level is automatically promote to VERBOSE.
- uniform log format to [FILE NAME]: [FUNC NAME]: [MSG]
- move from ALOG to LOG on DnsProxyListener
- adjust severity for some logs
- correct print format on uint8_t type

Bug: 128736560
Test: builds, boots
Test: atest resolv_integration_test
Change-Id: I0ff03824901168165bbe1f5abae9ff3e74db63d6
diff --git a/resolv/DnsProxyListener.cpp b/resolv/DnsProxyListener.cpp
index edd701c..b6eeaf3 100644
--- a/resolv/DnsProxyListener.cpp
+++ b/resolv/DnsProxyListener.cpp
@@ -38,7 +38,6 @@
 #include <android-base/stringprintf.h>
 #include <android/multinetwork.h>  // ResNsendFlags
 #include <cutils/misc.h>           // FIRST_APPLICATION_UID
-#include <log/log.h>
 #include <netdutils/OperationLimiter.h>
 #include <netdutils/Slice.h>
 #include <private/android_filesystem_config.h>  // AID_SYSTEM
@@ -74,9 +73,9 @@
 android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID);
 
 void logArguments(int argc, char** argv) {
-    if (!WOULD_LOG(DEBUG)) return;
+    if (!WOULD_LOG(VERBOSE)) return;
     for (int i = 0; i < argc; i++) {
-        ALOGD("argv[%i]=%s", i, argv[i]);
+        LOG(VERBOSE) << __func__ << ": argv[" << i << "]=" << (argv[i] ? argv[i] : "null");
     }
 }
 
@@ -300,7 +299,8 @@
 
     const std::shared_ptr<INetdEventListener> listener = ResolverEventReporter::getListener();
     if (!listener) {
-        ALOGE("DNS event not sent since NetdEventListenerService is unavailable.");
+        LOG(ERROR) << __func__
+                   << ": DNS event not sent since NetdEventListenerService is unavailable.";
         return;
     }
     const int latencyMs = latencyUs / 1000;
@@ -360,14 +360,13 @@
     if (!WOULD_LOG(DEBUG)) return;
     if (hp == nullptr) return;
 
-    ALOGD("DNS records:");
+    LOG(DEBUG) << __func__ << ": DNS records:";
     for (int i = 0; hp->h_addr_list[i] != nullptr; i++) {
         char ip_addr[INET6_ADDRSTRLEN];
         if (inet_ntop(hp->h_addrtype, hp->h_addr_list[i], ip_addr, sizeof(ip_addr)) != nullptr) {
-            ALOGD("[%d] %s, %d, %d, %s (%p)", i, hp->h_name ? hp->h_name : "null", hp->h_addrtype,
-                  hp->h_length, ip_addr, hp->h_addr_list[i]);
+            LOG(DEBUG) << __func__ << ": [" << i << "] " << hp->h_addrtype;
         } else {
-            ALOGD("[%d] numeric hostname translation fail (%d)", i, errno);
+            PLOG(DEBUG) << __func__ << ": [" << i << "] numeric hostname translation fail";
         }
     }
 }
@@ -378,29 +377,28 @@
 
     int i;
     const addrinfo* ai;
-    ALOGD("DNS records:");
+    LOG(DEBUG) << __func__ << ": DNS records:";
     for (ai = res, i = 0; ai; ai = ai->ai_next, i++) {
         if ((ai->ai_family != AF_INET) && (ai->ai_family != AF_INET6)) continue;
         char ip_addr[INET6_ADDRSTRLEN];
         int ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, ip_addr, sizeof(ip_addr), nullptr, 0,
                               NI_NUMERICHOST);
         if (!ret) {
-            ALOGD("[%d] 0x%x,%d,%d,%d,%d,%s,%s,%p", i, ai->ai_flags, ai->ai_family, ai->ai_socktype,
-                  ai->ai_protocol, ai->ai_addrlen, ai->ai_canonname ? ai->ai_canonname : "null",
-                  ip_addr, ai);
+            LOG(DEBUG) << __func__ << ": [" << i << "] " << ai->ai_flags << " " << ai->ai_family
+                       << " " << ai->ai_socktype << " " << ai->ai_protocol;
         } else {
-            ALOGD("[%d] numeric hostname translation fail (%d)", i, ret);
+            LOG(DEBUG) << __func__ << ": [" << i << "] numeric hostname translation fail " << ret;
         }
     }
 }
 
 bool isValidNat64Prefix(const netdutils::IPPrefix prefix) {
     if (prefix.family() != AF_INET6) {
-        ALOGE("Only IPv6 NAT64 prefixes are supported (%u)", prefix.family());
+        LOG(ERROR) << __func__ << ": Only IPv6 NAT64 prefixes are supported " << prefix.family();
         return false;
     }
     if (prefix.length() != 96) {
-        ALOGE("Only /96 NAT64 prefixes are supported (%d)", prefix.length());
+        LOG(ERROR) << __func__ << ": Only /96 NAT64 prefixes are supported " << prefix.length();
         return false;
     }
     return true;
@@ -427,11 +425,11 @@
         if (WOULD_LOG(DEBUG)) {
             char buf[INET6_ADDRSTRLEN];  // big enough for either IPv4 or IPv6
             inet_ntop(AF_INET, &iaOriginal.s_addr, buf, sizeof(buf));
-            ALOGD("DNS A record: %s", buf);
+            LOG(DEBUG) << __func__ << ": DNS A record: " << buf;
             inet_ntop(AF_INET6, &v6prefix->sin6_addr, buf, sizeof(buf));
-            ALOGD("NAT64 prefix: %s", buf);
+            LOG(DEBUG) << __func__ << ": NAT64 prefix: " << buf;
             inet_ntop(AF_INET6, ia6, buf, sizeof(buf));
-            ALOGD("DNS64 Synthesized AAAA record: %s", buf);
+            LOG(DEBUG) << __func__ << ": DNS64 Synthesized AAAA record: " << buf;
         }
     }
     hp->h_addrtype = AF_INET6;
@@ -465,11 +463,11 @@
         if (WOULD_LOG(DEBUG)) {
             char buf[INET6_ADDRSTRLEN];  // big enough for either IPv4 or IPv6
             inet_ntop(AF_INET, &sinOriginal.sin_addr.s_addr, buf, sizeof(buf));
-            ALOGD("DNS A record: %s", buf);
+            LOG(DEBUG) << __func__ << ": DNS A record: " << buf;
             inet_ntop(AF_INET6, &v6prefix->sin6_addr, buf, sizeof(buf));
-            ALOGD("NAT64 prefix: %s", buf);
+            LOG(DEBUG) << __func__ << ": NAT64 prefix: " << buf;
             inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof(buf));
-            ALOGD("DNS64 Synthesized AAAA record: %s", buf);
+            LOG(DEBUG) << __func__ << ": DNS64 Synthesized AAAA record: " << buf;
         }
     }
     logDnsQueryResult(result);
@@ -612,7 +610,7 @@
                 return;
             }
         } else {
-            ALOGE("getaddrinfo: from UID %d, max concurrent queries reached", uid);
+            LOG(ERROR) << __func__ << ": from UID " << uid << ", max concurrent queries reached";
             return;
         }
     }
@@ -631,9 +629,9 @@
 }
 
 void DnsProxyListener::GetAddrInfoHandler::run() {
-    ALOGD("GetAddrInfoHandler, now for %s / %s / {%u,%u,%u,%u,%u,%u}", mHost, mService,
-          mNetContext.app_netid, mNetContext.app_mark, mNetContext.dns_netid, mNetContext.dns_mark,
-          mNetContext.uid, mNetContext.flags);
+    LOG(DEBUG) << "GetAddrInfoHandler::run: {" << mNetContext.app_netid << " "
+               << mNetContext.app_mark << " " << mNetContext.dns_netid << " "
+               << mNetContext.dns_mark << " " << mNetContext.uid << " " << mNetContext.flags << "}";
 
     addrinfo* result = nullptr;
     Stopwatch s;
@@ -647,7 +645,8 @@
         // Note that this error code is currently not passed down to the client.
         // android_getaddrinfo_proxy() returns EAI_NODATA on any error.
         rv = EAI_MEMORY;
-        ALOGE("getaddrinfo: from UID %d, max concurrent queries reached", uid);
+        LOG(ERROR) << "GetAddrInfoHandler::run: from UID " << uid
+                   << ", max concurrent queries reached";
     }
 
     doDns64Synthesis(&rv, &result);
@@ -665,7 +664,7 @@
         }
         success = success && sendBE32(mClient, 0);
         if (!success) {
-            ALOGW("Error writing DNS result to client");
+            LOG(WARNING) << "GetAddrInfoHandler::run: Error writing DNS result to client";
         }
     }
     std::vector<std::string> ip_addrs;
@@ -702,7 +701,7 @@
     if (argc != 8) {
         char* msg = nullptr;
         asprintf( &msg, "Invalid number of arguments to getaddrinfo: %i", argc);
-        ALOGW("%s", msg);
+        LOG(WARNING) << "GetAddrInfoCmd::runCommand: " << (msg ? msg : "null");
         cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
         free(msg);
         return -1;
@@ -747,10 +746,6 @@
         hints->ai_protocol = ai_protocol;
     }
 
-    ALOGD("GetAddrInfoHandler for %s / %s / {%u,%u,%u,%u,%u}", name ? name : "[nullhost]",
-          service ? service : "[nullservice]", netcontext.app_netid, netcontext.app_mark,
-          netcontext.dns_netid, netcontext.dns_mark, netcontext.uid);
-
     DnsProxyListener::GetAddrInfoHandler* handler =
             new DnsProxyListener::GetAddrInfoHandler(cli, name, service, hints, netcontext);
     tryThreadOrError(cli, handler);
@@ -767,21 +762,24 @@
 
     const uid_t uid = cli->getUid();
     if (argc != 4) {
-        ALOGW("resnsend: from UID %d, invalid number of arguments to resnsend: %d", uid, argc);
+        LOG(WARNING) << "ResNSendCommand::runCommand: resnsend: from UID " << uid
+                     << ", invalid number of arguments to resnsend: " << argc;
         sendBE32(cli, -EINVAL);
         return -1;
     }
 
     unsigned netId;
     if (!simpleStrtoul(argv[1], &netId)) {
-        ALOGW("resnsend: from UID %d, invalid netId", uid);
+        LOG(WARNING) << "ResNSendCommand::runCommand: resnsend: from UID " << uid
+                     << ", invalid netId";
         sendBE32(cli, -EINVAL);
         return -1;
     }
 
     uint32_t flags;
     if (!simpleStrtoul(argv[2], &flags)) {
-        ALOGW("resnsend: from UID %d, invalid flags", uid);
+        LOG(WARNING) << "ResNSendCommand::runCommand: resnsend: from UID " << uid
+                     << ", invalid flags";
         sendBE32(cli, -EINVAL);
         return -1;
     }
@@ -807,9 +805,9 @@
 }
 
 void DnsProxyListener::ResNSendHandler::run() {
-    ALOGD("ResNSendHandler, now for %s %u/ {%u,%u,%u,%u,%u,%u}", mMsg.c_str(), mFlags,
-          mNetContext.app_netid, mNetContext.app_mark, mNetContext.dns_netid, mNetContext.dns_mark,
-          mNetContext.uid, mNetContext.flags);
+    LOG(DEBUG) << "ResNSendHandler::run: " << mFlags << " / {" << mNetContext.app_netid << " "
+               << mNetContext.app_mark << " " << mNetContext.dns_netid << " "
+               << mNetContext.dns_mark << " " << mNetContext.uid << " " << mNetContext.flags << "}";
 
     Stopwatch s;
     maybeFixupNetContext(&mNetContext);
@@ -834,7 +832,7 @@
     if (!parseQuery(msg.data(), msgLen, &original_query_id, &rr_type, &rr_name) ||
         !setQueryId(msg.data(), msgLen, arc4random_uniform(65536))) {
         // If the query couldn't be parsed, block the request.
-        ALOGW("resnsend: from UID %d, invalid query", uid);
+        LOG(WARNING) << "ResNSendHandler::run: resnsend: from UID " << uid << ", invalid query";
         sendBE32(mClient, -EINVAL);
         return;
     }
@@ -847,7 +845,8 @@
                                     &arcode, static_cast<ResNsendFlags>(mFlags));
         queryLimiter.finish(uid);
     } else {
-        ALOGW("resnsend: from UID %d, max concurrent queries reached", uid);
+        LOG(WARNING) << "ResNSendHandler::run: resnsend: from UID " << uid
+                     << ", max concurrent queries reached";
         nsendAns = -EBUSY;
     }
 
@@ -865,14 +864,14 @@
 
     // Send rcode
     if (!sendBE32(mClient, arcode)) {
-        ALOGW("resnsend: failed to send rcode to uid %d: %s", uid, strerror(errno));
+        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send rcode to uid " << uid;
         return;
     }
 
     // Restore query id and send answer
     if (!setQueryId(ansBuf.data(), nsendAns, original_query_id) ||
         !sendLenAndData(mClient, nsendAns, ansBuf.data())) {
-        ALOGW("resnsend: failed to send answer to uid %d: %s", uid, strerror(errno));
+        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send answer to uid " << uid;
         return;
     }
 
@@ -897,7 +896,7 @@
     if (argc != 4) {
         char* msg = nullptr;
         asprintf(&msg, "Invalid number of arguments to gethostbyname: %i", argc);
-        ALOGW("%s", msg);
+        LOG(WARNING) << "GetHostByNameCmd::runCommand: " << (msg ? msg : "null");
         cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
         free(msg);
         return -1;
@@ -960,7 +959,7 @@
             return;
         }
     } else {
-        ALOGE("gethostbyname: from UID %d, max concurrent queries reached", uid);
+        LOG(ERROR) << __func__ << ": from UID " << uid << ", max concurrent queries reached";
         return;
     }
 
@@ -972,8 +971,6 @@
 }
 
 void DnsProxyListener::GetHostByNameHandler::run() {
-    ALOGD("DnsProxyListener::GetHostByNameHandler::run");
-
     Stopwatch s;
     maybeFixupNetContext(&mNetContext);
     const uid_t uid = mClient->getUid();
@@ -984,15 +981,13 @@
         queryLimiter.finish(uid);
     } else {
         rv = EAI_MEMORY;
-        ALOGE("gethostbyname: from UID %d, max concurrent queries reached", uid);
+        LOG(ERROR) << "GetHostByNameHandler::run: from UID " << uid
+                   << ", max concurrent queries reached";
     }
 
     doDns64Synthesis(&rv, &hp);
     const int latencyUs = lround(s.timeTakenUs());
-
-    ALOGD("GetHostByNameHandler::run gethostbyname errno: %s hp->h_name = %s, name_len = %zu",
-          hp ? "success" : strerror(errno), (hp && hp->h_name) ? hp->h_name : "null",
-          (hp && hp->h_name) ? strlen(hp->h_name) + 1 : 0);
+    LOG(DEBUG) << "GetHostByNameHandler::run: errno: " << (hp ? "success" : strerror(errno));
 
     bool success = true;
     if (hp) {
@@ -1004,7 +999,7 @@
     }
 
     if (!success) {
-        ALOGW("GetHostByNameHandler: Error writing DNS result to client");
+        LOG(WARNING) << "GetHostByNameHandler::run: Error writing DNS result to client";
     }
 
     std::vector<std::string> ip_addrs;
@@ -1027,7 +1022,7 @@
     if (argc != 5) {
         char* msg = nullptr;
         asprintf(&msg, "Invalid number of arguments to gethostbyaddr: %i", argc);
-        ALOGW("%s", msg);
+        LOG(WARNING) << "GetHostByAddrCmd::runCommand: " << (msg ? msg : "null");
         cli->sendMsg(ResponseCode::CommandParameterError, msg, false);
         free(msg);
         return -1;
@@ -1046,7 +1041,7 @@
     if (result <= 0) {
         char* msg = nullptr;
         asprintf(&msg, "inet_pton(\"%s\") failed %s", addrStr, strerror(errno));
-        ALOGW("%s", msg);
+        LOG(WARNING) << "GetHostByAddrCmd::runCommand: " << (msg ? msg : "null");
         cli->sendMsg(ResponseCode::OperationFailed, msg, false);
         free(addr);
         free(msg);
@@ -1119,13 +1114,11 @@
             (*hpp)->h_length = sizeof(struct in6_addr);
         }
     } else {
-        ALOGE("gethostbyaddr: from UID %d, max concurrent queries reached", uid);
+        LOG(ERROR) << __func__ << ": from UID " << uid << ", max concurrent queries reached";
     }
 }
 
 void DnsProxyListener::GetHostByAddrHandler::run() {
-    ALOGD("DnsProxyListener::GetHostByAddrHandler::run");
-
     Stopwatch s;
     maybeFixupNetContext(&mNetContext);
     const uid_t uid = mClient->getUid();
@@ -1137,15 +1130,14 @@
         queryLimiter.finish(uid);
     } else {
         rv = EAI_MEMORY;
-        ALOGE("gethostbyaddr: from UID %d, max concurrent queries reached", uid);
+        LOG(ERROR) << "GetHostByAddrHandler::run: from UID " << uid
+                   << ", max concurrent queries reached";
     }
 
     doDns64ReverseLookup(&hp);
     const int latencyUs = int(s.timeTakenUs());
 
-    ALOGD("GetHostByAddrHandler::run gethostbyaddr result: %s hp->h_name = %s, name_len = %zu",
-          hp ? "success" : gai_strerror(rv), (hp && hp->h_name) ? hp->h_name : "null",
-          (hp && hp->h_name) ? strlen(hp->h_name) + 1 : 0);
+    LOG(DEBUG) << "GetHostByAddrHandler::run: result: " << (hp ? "success" : gai_strerror(rv));
 
     bool success = true;
     if (hp) {
@@ -1156,7 +1148,7 @@
     }
 
     if (!success) {
-        ALOGW("GetHostByAddrHandler: Error writing DNS result to client");
+        LOG(WARNING) << "GetHostByAddrHandler::run: Error writing DNS result to client";
     }
 
     reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYADDR, mNetContext, latencyUs, rv,
diff --git a/resolv/DnsResolver.cpp b/resolv/DnsResolver.cpp
index a9d2f85..822f860 100644
--- a/resolv/DnsResolver.cpp
+++ b/resolv/DnsResolver.cpp
@@ -27,7 +27,7 @@
 bool resolv_init(const ResolverNetdCallbacks& callbacks) {
     android::base::InitLogging(/*argv=*/nullptr);
     android::base::SetDefaultTag("libnetd_resolv");
-    LOG(INFO) << "Initializing resolver";
+    LOG(INFO) << __func__ << "Initializing resolver";
     const std::string logSeverityStr =
             android::base::GetProperty("persist.sys.nw_dns_resolver_log", "WARNING");
     android::base::SetMinimumLogSeverity(logSeverityStrToEnum(logSeverityStr));
@@ -60,16 +60,16 @@
 
 bool DnsResolver::start() {
     if (!verifyCallbacks()) {
-        LOG(ERROR) << "Callback verification failed";
+        LOG(ERROR) << __func__ << "Callback verification failed";
         return false;
     }
     if (mDnsProxyListener.startListener()) {
-        PLOG(ERROR) << "Unable to start DnsProxyListener";
+        PLOG(ERROR) << __func__ << "Unable to start DnsProxyListener";
         return false;
     }
     binder_status_t ret;
     if ((ret = DnsResolverService::start()) != STATUS_OK) {
-        LOG(ERROR) << "Unable to start DnsResolverService: " << ret;
+        LOG(ERROR) << __func__ << "Unable to start DnsResolverService: " << ret;
         return false;
     }
     return true;
diff --git a/resolv/getaddrinfo.cpp b/resolv/getaddrinfo.cpp
index 0a657df..b2429aa 100644
--- a/resolv/getaddrinfo.cpp
+++ b/resolv/getaddrinfo.cpp
@@ -361,7 +361,7 @@
             if (tmp.ai_socktype == ANY && ex.e_socktype != ANY) tmp.ai_socktype = ex.e_socktype;
             if (tmp.ai_protocol == ANY && ex.e_protocol != ANY) tmp.ai_protocol = ex.e_protocol;
 
-            LOG(DEBUG) << "explore_numeric: ai_family=" << tmp.ai_family
+            LOG(DEBUG) << __func__ << ": explore_numeric: ai_family=" << tmp.ai_family
                        << " ai_socktype=" << tmp.ai_socktype << " ai_protocol=" << tmp.ai_protocol;
             if (hostname == nullptr)
                 error = explore_null(&tmp, servname, &cur->ai_next);
@@ -409,7 +409,7 @@
             if (tmp.ai_socktype == ANY && ex.e_socktype != ANY) tmp.ai_socktype = ex.e_socktype;
             if (tmp.ai_protocol == ANY && ex.e_protocol != ANY) tmp.ai_protocol = ex.e_protocol;
 
-            LOG(DEBUG) << "explore_fqdn(): ai_family=" << tmp.ai_family
+            LOG(DEBUG) << __func__ << ": explore_fqdn(): ai_family=" << tmp.ai_family
                        << " ai_socktype=" << tmp.ai_socktype << " ai_protocol=" << tmp.ai_protocol;
             error = explore_fqdn(&tmp, hostname, servname, &cur->ai_next, netcontext);
 
@@ -478,6 +478,8 @@
     struct addrinfo sentinel;
     int error;
 
+    LOG(DEBUG) << __func__;
+
     assert(pai != NULL);
     /* servname may be NULL */
     assert(res != NULL);
@@ -589,6 +591,8 @@
     const char *cp, *scope, *addr;
     struct sockaddr_in6* sin6;
 
+    LOG(DEBUG) << __func__;
+
     assert(pai != NULL);
     /* hostname may be NULL */
     /* servname may be NULL */
@@ -936,9 +940,8 @@
             }
         } else if (type != qtype) {
             if (type != T_KEY && type != T_SIG)
-                LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
-                           << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
-                           << p_type(type) << "\"";
+                LOG(DEBUG) << __func__ << ": asked for \"" << qname << " " << p_class(C_IN) << " "
+                           << p_type(qtype) << "\", got type \"" << p_type(type) << "\"";
             cp += n;
             continue; /* XXX - had_error++ ? */
         }
@@ -946,8 +949,8 @@
             case T_A:
             case T_AAAA:
                 if (strcasecmp(canonname, bp) != 0) {
-                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << canonname
-                               << "\", got \"" << bp << "\"";
+                    LOG(DEBUG) << __func__ << ": asked for \"" << canonname << "\", got \"" << bp
+                               << "\"";
                     cp += n;
                     continue; /* XXX - had_error++ ? */
                 }
@@ -1589,7 +1592,7 @@
         answer = t->answer;
         anslen = t->anslen;
 
-        LOG(DEBUG) << __func__ << "(" << name << ", " << cl << ", " << type << ")";
+        LOG(DEBUG) << __func__ << ": (" << cl << ", " << type << ")";
 
         n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
         if (n > 0 && (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 && !retried)
@@ -1790,8 +1793,6 @@
 
     assert(name != NULL);
 
-    LOG(DEBUG) << __func__ << "(\"" << name << "\", " << (domain ? domain : "<null>") << ")";
-
     if (domain == NULL) {
         // Check for trailing '.'; copy without '.' if present.
         n = strlen(name);
diff --git a/resolv/gethnamaddr.cpp b/resolv/gethnamaddr.cpp
index efbbdc5..5a35dbb 100644
--- a/resolv/gethnamaddr.cpp
+++ b/resolv/gethnamaddr.cpp
@@ -277,17 +277,16 @@
         }
         if (type != qtype) {
             if (type != T_KEY && type != T_SIG)
-                LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
-                           << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
-                           << p_type(type) << "\"";
+                LOG(DEBUG) << __func__ << ": asked for \"" << qname << " " << p_class(C_IN) << " "
+                           << p_type(qtype) << "\", got type \"" << p_type(type) << "\"";
             cp += n;
             continue; /* XXX - had_error++ ? */
         }
         switch (type) {
             case T_PTR:
                 if (strcasecmp(tname, bp) != 0) {
-                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << "\", got \""
-                               << bp << "\"";
+                    LOG(DEBUG) << __func__ << ": asked for \"" << qname << "\", got \"" << bp
+                               << "\"";
                     cp += n;
                     continue; /* XXX - had_error++ ? */
                 }
@@ -314,8 +313,8 @@
             case T_A:
             case T_AAAA:
                 if (strcasecmp(hent->h_name, bp) != 0) {
-                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << hent->h_name
-                               << "\", got \"" << bp << "\"";
+                    LOG(DEBUG) << __func__ << ": asked for \"" << hent->h_name << "\", got \"" << bp
+                               << "\"";
                     cp += n;
                     continue; /* XXX - had_error++ ? */
                 }
@@ -342,13 +341,13 @@
                 bp += sizeof(align) - (size_t)((u_long) bp % sizeof(align));
 
                 if (bp + n >= ep) {
-                    LOG(DEBUG) << "size (" << n << ") too big";
+                    LOG(DEBUG) << __func__ << ": size (" << n << ") too big";
                     had_error++;
                     continue;
                 }
                 if (hap >= &addr_ptrs[MAXADDRS - 1]) {
                     if (!toobig++) {
-                        LOG(DEBUG) << "Too many addresses (" << MAXADDRS << ")";
+                        LOG(DEBUG) << __func__ << ": Too many addresses (" << MAXADDRS << ")";
                     }
                     cp += n;
                     continue;
@@ -784,7 +783,7 @@
     int herrno = NETDB_INTERNAL;
     n = res_nsearch(res, name, C_IN, type, buf->buf, (int) sizeof(buf->buf), &herrno);
     if (n < 0) {
-        LOG(DEBUG) << "res_nsearch failed (" << n << ")";
+        LOG(DEBUG) << __func__ << ": res_nsearch failed (" << n << ")";
         // Pass herrno to catch more detailed errors rather than EAI_NODATA.
         return herrnoToAiErrno(herrno);
     }
@@ -842,7 +841,7 @@
     int herrno = NETDB_INTERNAL;
     n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int) sizeof(buf->buf), &herrno);
     if (n < 0) {
-        LOG(DEBUG) << "res_nquery failed (" << n << ")";
+        LOG(DEBUG) << __func__ << ": res_nquery failed (" << n << ")";
         return herrnoToAiErrno(herrno);
     }
     hostent* hp =
diff --git a/resolv/res_cache.cpp b/resolv/res_cache.cpp
index 53122f6..8c329e6 100644
--- a/resolv/res_cache.cpp
+++ b/resolv/res_cache.cpp
@@ -304,7 +304,7 @@
     char *p = buff, *end = p + sizeof(buff);
 
     p = bprint_hexdump(p, end, base, len);
-    LOG(INFO) << buff;
+    LOG(INFO) << __func__ << ": " << buff;
 }
 
 static time_t _time_now(void) {
@@ -486,7 +486,7 @@
          * of the loop here */
     }
     /* malformed data */
-    LOG(INFO) << "malformed QNAME";
+    LOG(INFO) << __func__ << ": malformed QNAME";
     return 0;
 }
 
@@ -502,12 +502,12 @@
         !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_MX) &&
         !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_AAAA) &&
         !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_ALL)) {
-        LOG(INFO) << "unsupported TYPE";
+        LOG(INFO) << __func__ << ": unsupported TYPE";
         return 0;
     }
     /* CLASS must be IN */
     if (!_dnsPacket_checkBytes(packet, 2, DNS_CLASS_IN)) {
-        LOG(INFO) << "unsupported CLASS";
+        LOG(INFO) << __func__ << ": unsupported CLASS";
         return 0;
     }
 
@@ -522,14 +522,14 @@
     int qdCount, anCount, dnCount, arCount;
 
     if (p + DNS_HEADER_SIZE > packet->end) {
-        LOG(INFO) << "query packet too small";
+        LOG(INFO) << __func__ << ": query packet too small";
         return 0;
     }
 
     /* QR must be set to 0, opcode must be 0 and AA must be 0 */
     /* RA, Z, and RCODE must be 0 */
     if ((p[2] & 0xFC) != 0 || (p[3] & 0xCF) != 0) {
-        LOG(INFO) << "query packet flags unsupported";
+        LOG(INFO) << __func__ << ": query packet flags unsupported";
         return 0;
     }
 
@@ -558,12 +558,12 @@
     arCount = (p[10] << 8) | p[11];
 
     if (anCount != 0 || dnCount != 0 || arCount > 1) {
-        LOG(INFO) << "query packet contains non-query records";
+        LOG(INFO) << __func__ << ": query packet contains non-query records";
         return 0;
     }
 
     if (qdCount == 0) {
-        LOG(INFO) << "query packet doesn't contain query record";
+        LOG(INFO) << __func__ << ": query packet doesn't contain query record";
         return 0;
     }
 
@@ -820,7 +820,7 @@
         /* we rely on the bound checks at the start of the loop */
     }
     /* not the same, or one is malformed */
-    LOG(INFO) << "different DN";
+    LOG(INFO) << __func__ << ": different DN";
     return 0;
 }
 
@@ -868,12 +868,12 @@
 
     /* compare RD, ignore TC, see comment in _dnsPacket_checkQuery */
     if ((pack1->base[2] & 1) != (pack2->base[2] & 1)) {
-        LOG(INFO) << "different RD";
+        LOG(INFO) << __func__ << ": different RD";
         return 0;
     }
 
     if (pack1->base[3] != pack2->base[3]) {
-        LOG(INFO) << "different CD or AD";
+        LOG(INFO) << __func__ << ": different CD or AD";
         return 0;
     }
 
@@ -885,7 +885,7 @@
     count1 = _dnsPacket_readInt16(pack1);
     count2 = _dnsPacket_readInt16(pack2);
     if (count1 != count2 || count1 < 0) {
-        LOG(INFO) << "different QDCOUNT";
+        LOG(INFO) << __func__ << ": different QDCOUNT";
         return 0;
     }
 
@@ -897,14 +897,14 @@
     arcount1 = _dnsPacket_readInt16(pack1);
     arcount2 = _dnsPacket_readInt16(pack2);
     if (arcount1 != arcount2 || arcount1 < 0) {
-        LOG(INFO) << "different ARCOUNT";
+        LOG(INFO) << __func__ << ": different ARCOUNT";
         return 0;
     }
 
     /* compare the QDCOUNT QRs */
     for (; count1 > 0; count1--) {
         if (!_dnsPacket_isEqualQR(pack1, pack2)) {
-            LOG(INFO) << "different QR";
+            LOG(INFO) << __func__ << ": different QR";
             return 0;
         }
     }
@@ -912,7 +912,7 @@
     /* compare the ARCOUNT RRs */
     for (; arcount1 > 0; arcount1--) {
         if (!_dnsPacket_isEqualRR(pack1, pack2)) {
-            LOG(INFO) << "different additional RR";
+            LOG(INFO) << __func__ << ": different additional RR";
             return 0;
         }
     }
@@ -1019,15 +1019,15 @@
                         result = ttl;
                     }
                 } else {
-                    PLOG(INFO) << "ns_parserr failed ancount no = " << n;
+                    PLOG(INFO) << __func__ << ": ns_parserr failed ancount no = " << n;
                 }
             }
         }
     } else {
-        PLOG(INFO) << "ns_initparse failed";
+        PLOG(INFO) << __func__ << ": ns_initparse failed";
     }
 
-    LOG(INFO) << "TTL = " << result;
+    LOG(INFO) << __func__ << ": TTL = " << result;
     return result;
 }
 
@@ -1265,7 +1265,7 @@
     cache->num_entries = 0;
     cache->last_id = 0;
 
-    LOG(INFO) << "*** DNS CACHE FLUSHED ***";
+    LOG(INFO) << __func__ << ": *** DNS CACHE FLUSHED ***";
 }
 
 static resolv_cache* resolv_cache_create() {
@@ -1287,12 +1287,14 @@
 }
 
 static void dump_query(const uint8_t* query, int querylen) {
+    if (!WOULD_LOG(VERBOSE)) return;
+
     char temp[256], *p = temp, *end = p + sizeof(temp);
     DnsPacket pack[1];
 
     _dnsPacket_init(pack, query, querylen);
     p = dnsPacket_bprintQuery(pack, p, end);
-    LOG(INFO) << temp;
+    LOG(VERBOSE) << __func__ << ": " << temp;
 }
 
 static void cache_dump_mru(Cache* cache) {
@@ -1303,7 +1305,7 @@
     for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
         p = bprint(p, end, " %d", e->id);
 
-    LOG(INFO) << temp;
+    LOG(INFO) << __func__ << ": " << temp;
 }
 
 /* This function tries to find a key within the hash table
@@ -1376,7 +1378,7 @@
         LOG(INFO) << __func__ << ": OLDEST NOT IN HTABLE ?";
         return;
     }
-    LOG(INFO) << "Cache full - removing oldest";
+    LOG(INFO) << __func__ << ": Cache full - removing oldest";
     dump_query(oldest->query, oldest->querylen);
     _cache_remove_p(cache, lookup);
 }
@@ -1441,7 +1443,7 @@
     e = *lookup;
 
     if (e == NULL) {
-        LOG(INFO) << "NOT IN CACHE";
+        LOG(INFO) << __func__ << ": NOT IN CACHE";
         // If it is no-cache-store mode, we won't wait for possible query.
         if (flags & ANDROID_RESOLV_NO_CACHE_STORE) {
             return RESOLV_CACHE_SKIP;
@@ -1451,7 +1453,7 @@
             return RESOLV_CACHE_NOTFOUND;
 
         } else {
-            LOG(INFO) << "Waiting for previous request";
+            LOG(INFO) << __func__ << ": Waiting for previous request";
             // wait until (1) timeout OR
             //            (2) cv is notified AND no pending request matching the |key|
             // (cv notifier should delete pending request before sending notification.)
@@ -1482,7 +1484,7 @@
 
     /* remove stale entries here */
     if (now >= e->expires) {
-        LOG(INFO) << " NOT IN CACHE (STALE ENTRY " << *lookup << "DISCARDED)";
+        LOG(INFO) << __func__ << ": NOT IN CACHE (STALE ENTRY " << *lookup << "DISCARDED)";
         dump_query(e->query, e->querylen);
         _cache_remove_p(cache, lookup);
         return RESOLV_CACHE_NOTFOUND;
@@ -1491,7 +1493,7 @@
     *answerlen = e->answerlen;
     if (e->answerlen > answersize) {
         /* NOTE: we return UNSUPPORTED if the answer buffer is too short */
-        LOG(INFO) << " ANSWER TOO LONG";
+        LOG(INFO) << __func__ << ": ANSWER TOO LONG";
         return RESOLV_CACHE_UNSUPPORTED;
     }
 
@@ -1503,7 +1505,7 @@
         entry_mru_add(e, &cache->mru_list);
     }
 
-    LOG(INFO) << " FOUND IN CACHE entry=" << e;
+    LOG(INFO) << __func__ << ": FOUND IN CACHE entry=" << e;
     return RESOLV_CACHE_FOUND;
 }
 
@@ -1533,7 +1535,7 @@
     dump_query((u_char*)query, querylen);
     res_pquery((u_char*)answer, answerlen);
     if (kDumpData) {
-        LOG(INFO) << "answer:";
+        LOG(INFO) << __func__ << ": answer:";
         dump_bytes((u_char*)answer, answerlen);
     }
 
@@ -1846,7 +1848,7 @@
     if (statp == NULL) {
         return;
     }
-    LOG(INFO) << __func__ << "(netid=" << statp->netid << ")";
+    LOG(INFO) << __func__ << ": netid=" << statp->netid;
 
     std::lock_guard guard(cache_mutex);
     resolv_cache_info* info = find_cache_info_locked(statp->netid);
@@ -1893,8 +1895,8 @@
                                                int max_samples) {
     // Note: This function expects max_samples > 0, otherwise a (harmless) modification of the
     // allocated but supposedly unused memory for samples[0] will happen
-    LOG(INFO) << __func__ << ": adding sample to stats, next = " << stats->sample_next
-              << ", count = " << stats->sample_count;
+    LOG(INFO) << __func__ << ": adding sample to stats, next = " << unsigned(stats->sample_next)
+              << ", count = " << unsigned(stats->sample_count);
     stats->samples[stats->sample_next] = *sample;
     if (stats->sample_count < max_samples) {
         ++stats->sample_count;
diff --git a/resolv/res_debug.cpp b/resolv/res_debug.cpp
index f9225c0..482fdad 100644
--- a/resolv/res_debug.cpp
+++ b/resolv/res_debug.cpp
@@ -96,6 +96,7 @@
  */
 
 #define LOG_TAG "res_debug"
+#define DBG 0
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -161,7 +162,7 @@
     char* buf = (char*) malloc((size_t) buflen);
     if (buf == NULL) {
         dbprint(p, end, ";; memory allocation failure\n");
-        LOG(VERBOSE) << temp;
+        LOG(VERBOSE) << __func__ << ": " << temp;
         return;
     }
 
@@ -234,7 +235,7 @@
                     }
                     if (buf == NULL) {
                         p = dbprint(p, end, ";; memory allocation failure\n");
-                        LOG(VERBOSE) << temp;
+                        LOG(VERBOSE) << __func__ << ": " << temp;
                         return;
                     }
                     continue;
@@ -499,24 +500,23 @@
 
 android::base::LogSeverity logSeverityStrToEnum(const std::string& logSeverityStr) {
     android::base::LogSeverity logSeverityEnum;
-    if (logSeverityStr == "VERBOSE") {
-        logSeverityEnum = android::base::VERBOSE;
-    } else if (logSeverityStr == "DEBUG") {
-        logSeverityEnum = android::base::DEBUG;
+
+    if (logSeverityStr == "DEBUG") {
+        // *** enable verbose logging only when DBG is set. It prints sensitive data ***
+        if (DBG)
+            logSeverityEnum = android::base::VERBOSE;
+        else
+            logSeverityEnum = android::base::DEBUG;
     } else if (logSeverityStr == "INFO") {
         logSeverityEnum = android::base::INFO;
     } else if (logSeverityStr == "WARNING") {
         logSeverityEnum = android::base::WARNING;
     } else if (logSeverityStr == "ERROR") {
         logSeverityEnum = android::base::ERROR;
-    } else if (logSeverityStr == "FATAL_WITHOUT_ABORT") {
-        logSeverityEnum = android::base::FATAL_WITHOUT_ABORT;
-    } else if (logSeverityStr == "FATAL") {
-        logSeverityEnum = android::base::FATAL;
     } else {
         // Invalid parameter is treated as WARNING (default setting)
         logSeverityEnum = android::base::WARNING;
     }
-    LOG(INFO) << "logSeverityEnum " << logSeverityEnum;
+    LOG(INFO) << __func__ << ": " << logSeverityEnum;
     return logSeverityEnum;
 }
diff --git a/resolv/res_init.cpp b/resolv/res_init.cpp
index 7f11ce6..ceb3023 100644
--- a/resolv/res_init.cpp
+++ b/resolv/res_init.cpp
@@ -187,7 +187,7 @@
             dots--;
         }
         *pp = NULL;
-        LOG(DEBUG) << "res_init(): dnsrch list:";
+        LOG(DEBUG) << __func__ << ": dnsrch list:";
         for (pp = statp->dnsrch; *pp; pp++) LOG(DEBUG) << "\t" << *pp;
     }
 
@@ -204,7 +204,7 @@
     int i;
     res_state_ext* ext = statp->_u._ext.ext;
 
-    LOG(DEBUG) << ";; res_setoptions(\"" << options << "\", \"" << source << "\")...";
+    LOG(DEBUG) << "res_setoptions(\"" << options << "\", \"" << source << "\")...";
 
     while (*cp) {
         /* skip leading and inner runs of spaces */
@@ -216,14 +216,14 @@
                 statp->ndots = i;
             else
                 statp->ndots = RES_MAXNDOTS;
-            LOG(DEBUG) << ";;\tndots=" << statp->ndots;
+            LOG(DEBUG) << "\tndots=" << statp->ndots;
 
         } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
             if (!(statp->options & RES_DEBUG)) {
-                LOG(DEBUG) << ";; res_setoptions(\"" << options << "\", \"" << source << "\")..";
+                LOG(DEBUG) << "res_setoptions(\"" << options << "\", \"" << source << "\")..";
                 statp->options |= RES_DEBUG;
             }
-            LOG(DEBUG) << ";;\tdebug";
+            LOG(DEBUG) << "\tdebug";
 
         } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1) ||
                    !strncmp(cp, "no-tld-query", sizeof("no-tld-query") - 1)) {
diff --git a/resolv/res_mkquery.cpp b/resolv/res_mkquery.cpp
index 84a57b5..20d172c 100644
--- a/resolv/res_mkquery.cpp
+++ b/resolv/res_mkquery.cpp
@@ -113,8 +113,8 @@
     int n;
     u_char *dnptrs[20], **dpp, **lastdnptr;
 
-    LOG(DEBUG) << __func__ << "(" << _res_opcodes[op] << ", " << dname << ", " << p_class(cl)
-               << ", " << p_type(type) << ")";
+    LOG(DEBUG) << __func__ << ": (" << _res_opcodes[op] << ", " << p_class(cl) << ", "
+               << p_type(type) << ")";
 
     /*
      * Initialize header fields.
diff --git a/resolv/res_query.cpp b/resolv/res_query.cpp
index 0f7b54e..fbbcc31 100644
--- a/resolv/res_query.cpp
+++ b/resolv/res_query.cpp
@@ -122,13 +122,13 @@
 again:
     hp->rcode = NOERROR; /* default */
 
-    LOG(DEBUG) << ";; res_query(" << name << ", " << cl << ", " << type;
+    LOG(DEBUG) << __func__ << ": (" << 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) {
-        LOG(DEBUG) << ";; res_query: mkquery failed";
+        LOG(DEBUG) << __func__ << ": mkquery failed";
         *herrno = NO_RECOVERY;
         return n;
     }
@@ -137,11 +137,11 @@
         /* 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) {
-            LOG(DEBUG) << ";; res_nquery: retry without EDNS0";
+            LOG(DEBUG) << __func__ << ": retry without EDNS0";
             retried = true;
             goto again;
         }
-        LOG(DEBUG) << ";; res_query: send error";
+        LOG(DEBUG) << __func__ << ": 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
@@ -169,7 +169,7 @@
     }
 
     if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-        LOG(DEBUG) << ";; rcode = (" << p_rcode(hp->rcode)
+        LOG(DEBUG) << __func__ << ": rcode = (" << p_rcode(hp->rcode)
                    << "), counts = an:" << ntohs(hp->ancount) << " ns:" << ntohs(hp->nscount)
                    << " ar:" << ntohs(hp->arcount);
 
@@ -350,7 +350,7 @@
     int n, d;
 
     if (domain == NULL) {
-        LOG(DEBUG) << ";; res_nquerydomain(" << name << ", <Nil>, " << cl << ", " << type << ")";
+        LOG(DEBUG) << __func__ << ": (null, " << cl << ", " << type << ")";
         /*
          * Check for trailing '.';
          * copy without '.' if present.
@@ -367,8 +367,7 @@
         } else
             longname = name;
     } else {
-        LOG(DEBUG) << ";; res_nquerydomain(" << name << ", " << domain << ", " << cl << ", " << type
-                   << ")";
+        LOG(DEBUG) << __func__ << ": (" << cl << ", " << type << ")";
         n = strlen(name);
         d = strlen(domain);
         if (n + d + 1 >= MAXDNAME) {
diff --git a/resolv/res_send.cpp b/resolv/res_send.cpp
index daa86ec..a09887d 100644
--- a/resolv/res_send.cpp
+++ b/resolv/res_send.cpp
@@ -555,7 +555,8 @@
             [[maybe_unused]] char abuf[NI_MAXHOST];
 
             if (getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf), NULL, 0, niflags) == 0)
-                LOG(DEBUG) << "Querying server (# " << ns + 1 << ") address = " << abuf;
+                LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1
+                           << ") address = " << abuf;
 
             if (v_circuit) {
                 /* Use VC; at most one attempt per server. */
@@ -577,7 +578,7 @@
                                                             params.max_samples);
                 }
 
-                LOG(INFO) << "used send_vc " << n;
+                LOG(INFO) << __func__ << ": used send_vc " << n;
 
                 if (n < 0) {
                     _resolv_cache_query_failed(statp->netid, buf, buflen, flags);
@@ -588,7 +589,7 @@
                 resplen = n;
             } else {
                 /* Use datagrams. */
-                LOG(INFO) << "using send_dg";
+                LOG(INFO) << __func__ << ": using send_dg";
 
                 n = send_dg(statp, &params, buf, buflen, ans, anssiz, &terrno, ns, &v_circuit,
                             &gotsomewhere, &now, rcode, &delay);
@@ -601,7 +602,7 @@
                                                             params.max_samples);
                 }
 
-                LOG(INFO) << "used send_dg " << n;
+                LOG(INFO) << __func__ << ": used send_dg " << n;
 
                 if (n < 0) {
                     _resolv_cache_query_failed(statp->netid, buf, buflen, flags);
@@ -613,7 +614,7 @@
                 resplen = n;
             }
 
-            LOG(DEBUG) << "got answer:";
+            LOG(DEBUG) << __func__ << ": got answer:";
             res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
 
             if (cache_status == RESOLV_CACHE_NOTFOUND) {
@@ -695,7 +696,7 @@
     if (msec < 1000) {
         msec = 1000;  // Use at least 1000ms
     }
-    LOG(INFO) << "using timeout of " << msec << " msec";
+    LOG(INFO) << __func__ << ": using timeout of " << msec << " msec";
 
     struct timespec result;
     result.tv_sec = msec / 1000;
@@ -716,7 +717,7 @@
     u_short len;
     u_char* cp;
 
-    LOG(INFO) << "using send_vc";
+    LOG(INFO) << __func__ << ": using send_vc";
 
     nsap = get_nsaddr(statp, (size_t) ns);
     nsaplen = get_salen(nsap);
@@ -839,7 +840,7 @@
     }
     resplen = ns_get16(ans);
     if (resplen > anssiz) {
-        LOG(DEBUG) << "response truncated";
+        LOG(DEBUG) << __func__ << ": response truncated";
         truncating = 1;
         len = anssiz;
     } else
@@ -848,7 +849,7 @@
         /*
          * Undersized message.
          */
-        LOG(DEBUG) << "undersized: " << len;
+        LOG(DEBUG) << __func__ << ": undersized: " << len;
         *terrno = EMSGSIZE;
         res_nclose(statp);
         return (0);
@@ -889,7 +890,7 @@
      * wait for the correct one.
      */
     if (hp->id != anhp->id) {
-        LOG(DEBUG) << "old answer (unexpected):";
+        LOG(DEBUG) << __func__ << ": ld answer (unexpected):";
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         goto read_len;
     }
@@ -922,7 +923,7 @@
     if (res != 0) {
         struct timespec now = evNowTime();
         struct timespec finish = evAddTime(now, timeout);
-        LOG(INFO) << sock << " send_vc";
+        LOG(INFO) << __func__ << ": " << sock << " send_vc";
         res = retrying_poll(sock, POLLIN | POLLOUT, &finish);
         if (res <= 0) {
             res = -1;
@@ -930,7 +931,7 @@
     }
 done:
     fcntl(sock, F_SETFL, origflags);
-    LOG(INFO) << sock << " connect_with_const timeout returning " << res;
+    LOG(INFO) << __func__ << ": " << sock << " connect_with_const timeout returning " << res;
     return res;
 }
 
@@ -938,7 +939,7 @@
     struct timespec now, timeout;
 
 retry:
-    LOG(INFO) << "  " << sock << " retrying_poll";
+    LOG(INFO) << __func__ << ": " << sock << " retrying_poll";
 
     now = evNowTime();
     if (evCmpTime(*finish, now) > 0)
@@ -948,13 +949,13 @@
     struct pollfd fds = {.fd = sock, .events = events};
     int n = ppoll(&fds, 1, &timeout, /*sigmask=*/NULL);
     if (n == 0) {
-        LOG(INFO) << "  " << sock << "retrying_poll timeout";
+        LOG(INFO) << __func__ << ": " << sock << "retrying_poll timeout";
         errno = ETIMEDOUT;
         return 0;
     }
     if (n < 0) {
         if (errno == EINTR) goto retry;
-        PLOG(INFO) << "  " << sock << " retrying_poll failed";
+        PLOG(INFO) << __func__ << ": " << sock << " retrying_poll failed";
         return n;
     }
     if (fds.revents & (POLLIN | POLLOUT | POLLERR)) {
@@ -962,11 +963,11 @@
         socklen_t len = sizeof(error);
         if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
             errno = error;
-            PLOG(INFO) << "  " << sock << " retrying_poll getsockopt failed";
+            PLOG(INFO) << __func__ << ": " << sock << " retrying_poll getsockopt failed";
             return -1;
         }
     }
-    LOG(INFO) << "  " << sock << " retrying_poll returning " << n;
+    LOG(INFO) << __func__ << ": " << sock << " retrying_poll returning " << n;
     return n;
 }
 
@@ -1033,7 +1034,7 @@
             return (0);
         }
 #endif /* !CANNOT_CONNECT_DGRAM */
-        LOG(DEBUG) << "new DG socket";
+        LOG(DEBUG) << __func__ << ": new DG socket";
     }
     s = statp->_u._ext.nssocks[ns];
 #ifndef CANNOT_CONNECT_DGRAM
@@ -1059,7 +1060,7 @@
 
     if (n == 0) {
         *rcode = RCODE_TIMEOUT;
-        LOG(DEBUG) << "timeout";
+        LOG(DEBUG) << __func__ << ": timeout";
         *gotsomewhere = 1;
         return 0;
     }
@@ -1082,7 +1083,7 @@
         /*
          * Undersized message.
          */
-        LOG(DEBUG) << "undersized: " << resplen;
+        LOG(DEBUG) << __func__ << ": undersized: " << resplen;
         *terrno = EMSGSIZE;
         res_nclose(statp);
         return 0;
@@ -1093,7 +1094,7 @@
          * XXX - potential security hazard could
          *	 be detected here.
          */
-        LOG(DEBUG) << "old answer:";
+        LOG(DEBUG) << __func__ << ": old answer:";
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         goto retry;
     }
@@ -1104,7 +1105,7 @@
          * XXX - potential security hazard could
          *	 be detected here.
          */
-        LOG(DEBUG) << "not our server:";
+        LOG(DEBUG) << __func__ << ": not our server:";
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         goto retry;
     }
@@ -1114,7 +1115,7 @@
          * The case has to be captured here, as FORMERR packet do not
          * carry query section, hence res_queriesmatch() returns 0.
          */
-        LOG(DEBUG) << "server rejected query with EDNS0:";
+        LOG(DEBUG) << __func__ << ": server rejected query with EDNS0:";
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         /* record the error */
         statp->_flags |= RES_F_EDNS0ERR;
@@ -1128,14 +1129,14 @@
          * XXX - potential security hazard could
          *	 be detected here.
          */
-        LOG(DEBUG) << "wrong query name:";
+        LOG(DEBUG) << __func__ << ": wrong query name:";
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         goto retry;
     }
     done = evNowTime();
     *delay = _res_stats_calculate_rtt(&done, &now);
     if (anhp->rcode == SERVFAIL || anhp->rcode == NOTIMP || anhp->rcode == REFUSED) {
-        LOG(DEBUG) << "server rejected query:";
+        LOG(DEBUG) << __func__ << ": server rejected query:";
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         res_nclose(statp);
         *rcode = anhp->rcode;
@@ -1146,7 +1147,7 @@
          * To get the rest of answer,
          * use TCP with same server.
          */
-        LOG(DEBUG) << "truncated answer";
+        LOG(DEBUG) << __func__ << ": truncated answer";
         *v_circuit = 1;
         res_nclose(statp);
         return 1;
@@ -1176,7 +1177,7 @@
             strncpy(sbuf, "?", sizeof(sbuf) - 1);
             sbuf[sizeof(sbuf) - 1] = '\0';
         }
-        LOG(DEBUG) << "res_send: " << string << " ([" << hbuf << "]." << sbuf
+        LOG(DEBUG) << __func__ << ": " << string << " ([" << hbuf << "]." << sbuf
                    << "): " << strerror(error);
     }
     errno = save;
@@ -1184,7 +1185,7 @@
 
 static void Perror(const res_state statp, const char* string, int error) {
     if ((statp->options & RES_DEBUG) != 0U) {
-        LOG(DEBUG) << "res_send: " << string << ": " << strerror(error);
+        LOG(DEBUG) << __func__ << ": " << string << ": " << strerror(error);
     }
 }
 
diff --git a/resolv/res_stats.cpp b/resolv/res_stats.cpp
index cfc5e6f..cf64949 100644
--- a/resolv/res_stats.cpp
+++ b/resolv/res_stats.cpp
@@ -120,22 +120,22 @@
                                     &rtt_avg, &last_sample_time);
     if (successes >= 0 && errors >= 0 && timeouts >= 0) {
         int total = successes + errors + timeouts;
-        LOG(INFO) << "NS stats: S " << successes << " + E " << errors << " + T " << timeouts
-                  << " + I " << internal_errors << " = " << total << ", rtt = " << rtt_avg
-                  << ", min_samples = " << params->min_samples;
+        LOG(INFO) << __func__ << ": NS stats: S " << successes << " + E " << errors << " + T "
+                  << timeouts << " + I " << internal_errors << " = " << total
+                  << ", rtt = " << rtt_avg << ", min_samples = " << unsigned(params->min_samples);
         if (total >= params->min_samples && (errors > 0 || timeouts > 0)) {
             int success_rate = successes * 100 / total;
-            LOG(INFO) << "success rate " << success_rate;
+            LOG(INFO) << __func__ << ": success rate " << success_rate;
             if (success_rate < params->success_threshold) {
                 time_t now = time(NULL);
                 if (now - last_sample_time > params->sample_validity) {
                     // Note: It might be worth considering to expire old servers after their expiry
                     // date has been reached, however the code for returning the ring buffer to its
                     // previous non-circular state would induce additional complexity.
-                    LOG(INFO) << "samples stale, retrying server";
+                    LOG(INFO) << __func__ << ": samples stale, retrying server";
                     _res_stats_clear_samples(stats);
                 } else {
-                    LOG(INFO) << "too many resolution errors, ignoring server";
+                    LOG(INFO) << __func__ << ": too many resolution errors, ignoring server";
                     return 0;
                 }
             }