Improve logging (#51)

* Improve logging

* fix test
This commit is contained in:
Frank Olbricht
2020-06-07 13:24:51 -06:00
committed by GitHub
parent 6ae21640c8
commit 6c59cb1a7c
38 changed files with 232 additions and 216 deletions

View File

@@ -2,7 +2,6 @@ package rdns
import (
"crypto/tls"
"fmt"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
@@ -10,6 +9,7 @@ import (
// DNSClient represents a simple DNS resolver for UDP or TCP.
type DNSClient struct {
id string
endpoint string
net string
pipeline *Pipeline
@@ -19,12 +19,13 @@ var _ Resolver = &DNSClient{}
// NewDNSClient returns a new instance of DNSClient which is a plain DNS resolver
// that supports pipelining over a single connection.
func NewDNSClient(endpoint, net string) *DNSClient {
func NewDNSClient(id, endpoint, net string) *DNSClient {
client := &dns.Client{
Net: net,
TLSConfig: &tls.Config{},
}
return &DNSClient{
id: id,
net: net,
endpoint: endpoint,
pipeline: NewPipeline(endpoint, client),
@@ -34,6 +35,7 @@ func NewDNSClient(endpoint, net string) *DNSClient {
// Resolve a DNS query.
func (d *DNSClient) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
Log.WithFields(logrus.Fields{
"id": d.id,
"client": ci.SourceIP,
"qname": qName(q),
"resolver": d.endpoint,
@@ -46,5 +48,5 @@ func (d *DNSClient) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
}
func (d *DNSClient) String() string {
return fmt.Sprintf("DNS(%s)", d.endpoint)
return d.id
}