diff --git a/minidns-client/src/main/java/org/minidns/DnsClient.java b/minidns-client/src/main/java/org/minidns/DnsClient.java index c806aa97..0a012a93 100644 --- a/minidns-client/src/main/java/org/minidns/DnsClient.java +++ b/minidns-client/src/main/java/org/minidns/DnsClient.java @@ -248,6 +248,7 @@ protected MiniDnsFuture queryAsync(DnsMessage.Build */ public static List findDNS() { List res = null; + final Level TRACE_LOG_LEVEL = Level.FINE; for (DnsServerLookupMechanism mechanism : LOOKUP_MECHANISMS) { try { res = mechanism.getDnsServerAddresses(); @@ -255,9 +256,25 @@ public static List findDNS() { LOGGER.log(Level.WARNING, "Could not lookup DNS server", exception); } if (res == null) { + LOGGER.log(TRACE_LOG_LEVEL, "DnsServerLookupMechanism '" + mechanism.getName() + "' did not return any DNS server"); continue; } + if (LOGGER.isLoggable(TRACE_LOG_LEVEL)) { + // TODO: Use String.join() once MiniDNS is Android API 26 (or higher). + StringBuilder sb = new StringBuilder(); + for (Iterator it = res.iterator(); it.hasNext();) { + String s = it.next(); + sb.append(s); + if (it.hasNext()) { + sb.append(", "); + } + } + String dnsServers = sb.toString(); + LOGGER.log(TRACE_LOG_LEVEL, "DnsServerLookupMechanism '{0}' returned the following DNS servers: {1}", + new Object[] { mechanism.getName(), dnsServers }); + } + assert !res.isEmpty(); // We could cache if res only contains IP addresses and avoid the verification in case. Not sure if its really that beneficial