github.com/EagleQL/Xray-core@v1.4.3/common/log/dns.go (about) 1 package log 2 3 import ( 4 "net" 5 "strings" 6 "time" 7 ) 8 9 type DNSLog struct { 10 Server string 11 Domain string 12 Result []net.IP 13 Status dnsStatus 14 Elapsed time.Duration 15 Error error 16 } 17 18 func (l *DNSLog) String() string { 19 builder := &strings.Builder{} 20 21 // Server got answer: domain -> [ip1, ip2] 23ms 22 builder.WriteString(l.Server) 23 builder.WriteString(" ") 24 builder.WriteString(string(l.Status)) 25 builder.WriteString(" ") 26 builder.WriteString(l.Domain) 27 builder.WriteString(" -> [") 28 builder.WriteString(joinNetIP(l.Result)) 29 builder.WriteString("]") 30 31 if l.Elapsed > 0 { 32 builder.WriteString(" ") 33 builder.WriteString(l.Elapsed.String()) 34 } 35 if l.Error != nil { 36 builder.WriteString(" <") 37 builder.WriteString(l.Error.Error()) 38 builder.WriteString(">") 39 } 40 return builder.String() 41 } 42 43 type dnsStatus string 44 45 var ( 46 DNSQueried = dnsStatus("got answer:") 47 DNSCacheHit = dnsStatus("cache HIT:") 48 ) 49 50 func joinNetIP(ips []net.IP) string { 51 if len(ips) == 0 { 52 return "" 53 } 54 sips := make([]string, 0, len(ips)) 55 for _, ip := range ips { 56 sips = append(sips, ip.String()) 57 } 58 return strings.Join(sips, ", ") 59 }