From 10a3860fad3b64428cf81375c474fb35c403d266 Mon Sep 17 00:00:00 2001 From: xvzc Date: Wed, 31 Jul 2024 20:47:19 +0900 Subject: [PATCH] enhance logging for dns --- dns/dns.go | 12 ++++++------ proxy/proxy.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dns/dns.go b/dns/dns.go index fb1f236..deb174b 100644 --- a/dns/dns.go +++ b/dns/dns.go @@ -4,8 +4,8 @@ import ( "context" "errors" "regexp" + "strconv" "time" - "strconv" "github.com/likexian/doh" dohDns "github.com/likexian/doh/dns" @@ -53,12 +53,12 @@ func (d *DnsResolver) Lookup(domain string) (string, error) { for _, answer := range response.Answer { if record, ok := answer.(*dns.A); ok { - log.Debug("[DNS] resolved dns for "+domain+": ", record.A.String()) + log.Debug("[DNS] resolved ", domain, ": ", record.A.String()) return record.A.String(), nil } } - return "", errors.New("couldn not resolve the domain") + return "", errors.New("no record found") } func dohLookup(domain string) (string, error) { @@ -68,7 +68,7 @@ func dohLookup(domain string) (string, error) { rsp, err := c.Query(ctx, dohDns.Domain(domain), dohDns.TypeA) if err != nil { - return "", errors.New("could not resolve the domain") + return "", errors.New("could not resolve the domain") } // doh dns answer answer := rsp.Answer @@ -79,12 +79,12 @@ func dohLookup(domain string) (string, error) { continue } - log.Debug("[DOH] resolved dns for "+domain+": ", a.Data) + log.Debug("[DOH] resolved ", domain, ": ", a.Data) return a.Data, nil } // close the client c.Close() - return "", errors.New("couldn not resolve the domain") + return "", errors.New("no record found") } diff --git a/proxy/proxy.go b/proxy/proxy.go index bcb4c6c..03913c3 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -76,7 +76,7 @@ func (pxy *Proxy) Start() { ip, err := pxy.resolver.Lookup(pkt.Domain()) if err != nil { - log.Error("[PROXY] Error looking up for domain with ", pkt.Domain(), " ", err) + log.Error("[PROXY] Error while dns lookup: ", pkt.Domain(), " ", err) conn.Write([]byte(pkt.Version() + " 502 Bad Gateway\r\n\r\n")) conn.Close() return