53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
func logWildcardSmartDNSTrace(mode DNSMode, source string, pairs [][2]string, wildcardIPCount int) {
|
|
lowMode := strings.ToLower(strings.TrimSpace(string(mode.Mode)))
|
|
if lowMode != string(DNSModeHybridWildcard) && lowMode != string(DNSModeSmartDNS) {
|
|
return
|
|
}
|
|
|
|
hostMap := wildcardHostIPMap(pairs)
|
|
hosts := make([]string, 0, len(hostMap))
|
|
for host := range hostMap {
|
|
hosts = append(hosts, host)
|
|
}
|
|
sort.Strings(hosts)
|
|
|
|
const maxHostsLog = 200
|
|
omitted := 0
|
|
if len(hosts) > maxHostsLog {
|
|
omitted = len(hosts) - maxHostsLog
|
|
}
|
|
|
|
appendTraceLineTo(
|
|
smartdnsLogPath,
|
|
"smartdns",
|
|
fmt.Sprintf(
|
|
"wildcard sync: mode=%s source=%s domains=%d ips=%d logged=%d omitted=%d map=%s",
|
|
mode.Mode, source, len(hosts), wildcardIPCount, len(hosts)-omitted, omitted, lastIPsMapDyn,
|
|
),
|
|
)
|
|
|
|
for i, host := range hosts {
|
|
if i >= maxHostsLog {
|
|
appendTraceLineTo(
|
|
smartdnsLogPath,
|
|
"smartdns",
|
|
fmt.Sprintf("wildcard sync: trace truncated, %d domains not shown (see %s)", omitted, lastIPsMapDyn),
|
|
)
|
|
return
|
|
}
|
|
appendTraceLineTo(
|
|
smartdnsLogPath,
|
|
"smartdns",
|
|
fmt.Sprintf("wildcard add: %s -> %s", host, strings.Join(hostMap[host], ", ")),
|
|
)
|
|
}
|
|
}
|