a) DnsResolver log的默认等级
log标签TAG为resolv,DnsResolverlog打印等级:
- 在android 11(R),默认等级为WARNING
- 在android 12(S),默认等级为根据系统版本为userdebug或user/release来区分。
//如果是userdebug版本,则log等级为Debug,
//如果非userdebug版本,则log等级为WARNING
b)控制调整DnsResolver log的命令
此代码使用LOG(X)进行日志记录。日志级别为VERBOSE、DEBUG、INFO、WARNING和ERROR。
默认设置为WARNING或DEBUG,将显示与WARNING和ERROR相关的日志。
如果希望启用DEBUG级日志,可用如下命令:
adb shell service call dnsresover 10 i32 1
如果希望启用VERBOSE级日志,可用如下命令:
adb shell service call dnsresover 10 i32 0
VERBOSE 0
DEBUG 1
INFO 2
WARNING 3
ERROR 4
c) android 12中 frameworks 中初始化DnsResolver log等级的代码
文件:/packages/modules/DnsResolver/DnsResolver.cpp
bool resolv_init(const ResolverNetdCallbacks* callbacks) {
android::base::InitLogging(/*argv=*/nullptr);
android::base::SetDefaultTag("libnetd_resolv");
LOG(INFO) << __func__ << ": Initializing resolver";
// TODO(b/170539625): restore log level to WARNING after clarifying flaky tests.
//这里初始化DnsResolver 的log等级:
//如果是userdebug版本,则log等级为Debug,
//如果非userdebug版本,则log等级为WARNING
resolv_set_log_severity(isUserDebugBuild() ? android::base::DEBUG : android::base::WARNING);
using android::net::gApiLevel;
gApiLevel = getApiLevel();
using android::net::gResNetdCallbacks;
gResNetdCallbacks.check_calling_permission = callbacks->check_calling_permission;
gResNetdCallbacks.get_network_context = callbacks->get_network_context;
gResNetdCallbacks.log = callbacks->log;
if (gApiLevel >= 30) {
gResNetdCallbacks.tagSocket = callbacks->tagSocket;
gResNetdCallbacks.evaluate_domain_name = callbacks->evaluate_domain_name;
}
android::net::gDnsResolv = android::net::DnsResolver::getInstance();
return android::net::gDnsResolv->start();
}
int DnsResolver::setLogSeverity(int32_t logSeverity) {
return resolv_set_log_severity(logSeverity);
}
01-05 14:49:30.801 355 14115 Iresolv :resolv_populate_res_for_net: netid=100
01-05 14:49:30.801 355 14115 D libnetd_resolv: dns_gethtbyname: res_nsearch failed (-1)
01-05 14:49:30.801 355 14115 Dresolv : GetHostByNameHandler::run: result: No address associated with hostname
01-05 14:49:30.941 355 14116 D resolv : res_nquerydomain: (null, 1, 1)
01-05 14:49:30.941 355 14116 D resolv : res_nquery: (1, 1)
01-05 14:49:30.941 355 14116 D resolv : res_nmkquery: (QUERY, IN, A)
01-05 14:49:30.941 355 14116 D resolv : res_nsend
01-05 14:49:30.941 355 14116 I resolv : resolv_cache_lookup: lookup
01-05 14:49:30.941 355 14116 I resolv : resolv_cache_lookup: FOUND IN CACHE entry=0xf04673c0
01-05 14:49:30.941 355 14116 D resolv : res_nquery: rcode = (NXDOMAIN), counts = an:0 ns:1 ar:0
01-05 14:49:30.941 355 14116 I resolv : resolv_populate_res_for_net: netid=100
01-05 14:49:30.941 355 14116 D libnetd_resolv: dns_gethtbyname: res_nsearch failed (-1)
01-05 14:49:30.941 355 14116 D resolv : GetHostByNameHandler::run: result: No address associated with hostname
01-05 14:49:31.079 355 14119 D resolv : res_nquerydomain: (null, 1, 1)
01-05 14:49:31.079 355 14119 D resolv : res_nquery: (1, 1)
01-05 14:49:31.079 355 14119 D resolv : res_nmkquery: (QUERY, IN, A)
01-05 14:49:31.079 355 14119 D resolv : res_nsend
01-05 14:49:31.079 355 14119 I resolv : resolv_cache_lookup: lookup
01-05 14:49:31.079 355 14119 I resolv : resolv_cache_lookup: FOUND IN CACHE entry=0xf04673c0
01-05 14:49:31.079 355 14119 D resolv : res_nquery: rcode = (NXDOMAIN), counts = an:0 ns:1 ar:0
01-05 14:49:31.080 355 14119 I resolv : resolv_populate_res_for_net: netid=100
01-05 14:49:31.080 355 14119 D libnetd_resolv: dns_gethtbyname: res_nsearch failed (-1)
01-05 14:49:31.080 355 14119 D resolv : GetHostByNameHandler::run: result: No address associated with hostname
01-05 14:49:31.221 355 14120 D resolv : res_nquerydomain: (null, 1, 1)
01-05 14:49:31.221 355 14120 D resolv : res_nquery: (1, 1)
01-05 14:49:31.221 355 14120 D resolv : res_nmkquery: (QUERY, IN, A)
01-05 14:49:31.221 355 14120 D resolv : res_nsend
01-05 14:49:31.221 355 14120 I resolv : resolv_cache_lookup: lookup
01-05 14:49:31.221 355 14120 I resolv : resolv_cache_lookup: FOUND IN CACHE entry=0xf04673c0
01-05 14:49:31.221 355 14120 D resolv : res_nquery: rcode = (NXDOMAIN), counts = an:0 ns:1 ar:0
01-05 14:49:31.221 355 14120 I resolv : resolv_populate_res_for_net: netid=100
01-05 14:49:31.221 355 14120 D libnetd_resolv: dns_gethtbyname: res_nsearch failed (-1)
01-05 14:49:31.221 355 14120 D resolv : GetHostByNameHandler::run: result: No address associated with hostname
01-05 14:49:31.361 355 14121 D resolv : res_nquerydomain: (null, 1, 1)
01-05 14:49:31.361 355 14121 D resolv : res_nquery: (1, 1)
01-05 14:49:31.361 355 14121 D resolv : res_nmkquery: (QUERY, IN, A)
01-05 14:49:31.361 355 14121 D resolv : res_nsend
01-05 14:49:31.361 355 14121 I resolv : resolv_cache_lookup: lookup
01-05 14:49:31.361 355 14121 I resolv : resolv_cache_lookup: FOUND IN CACHE entry=0xf04673c0
01-05 14:49:31.361 355 14121 D resolv : res_nquery: rcode = (NXDOMAIN), counts = an:0 ns:1 ar:0
01-05 14:49:31.361 355 14121 I resolv : resolv_populate_res_for_net: netid=100
01-05 14:49:31.361 355 14121 D libnetd_resolv: dns_gethtbyname: res_nsearch failed (-1)
01-05 14:49:31.361 355 14121 D resolv : GetHostByNameHandler::run: result: No address associated with hostname
01-05 14:49:31.470 355 14123 D resolv : res_nquerydomain: (null, 1, 1)
01-05 14:49:31.470 355 14123 D resolv : res_nquery: (1, 1)
01-05 14:49:31.470 355 14123 D resolv : res_nmkquery: (QUERY, IN, A)
01-05 14:49:31.470 355 14123 D resolv : res_nsend
01-05 14:49:31.470 355 14123 I resolv : resolv_cache_lookup: lookup