Disable logging by default

This commit is contained in:
Star Brilliant
2017-11-25 15:05:15 +08:00
parent f2d77e4a74
commit 2577b720c7
4 changed files with 19 additions and 7 deletions
+6 -2
View File
@@ -40,17 +40,19 @@ type Client struct {
bootstrap string
timeout uint
noECS bool
verbose bool
udpServer *dns.Server
tcpServer *dns.Server
httpClient *http.Client
}
func NewClient(addr, upstream, bootstrap string, timeout uint, noECS bool) (c *Client, err error) {
func NewClient(addr, upstream, bootstrap string, timeout uint, noECS, verbose bool) (c *Client, err error) {
c = &Client {
addr: addr,
upstream: upstream,
timeout: timeout,
noECS: noECS,
verbose: verbose,
}
c.udpServer = &dns.Server {
Addr: addr,
@@ -140,7 +142,9 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
questionType = strconv.Itoa(int(question.Qtype))
}
fmt.Printf("%s - - [%s] \"%s IN %s\"\n", w.RemoteAddr(), time.Now().Format("02/Jan/2006:15:04:05 -0700"), questionName, questionType)
if c.verbose{
fmt.Printf("%s - - [%s] \"%s IN %s\"\n", w.RemoteAddr(), time.Now().Format("02/Jan/2006:15:04:05 -0700"), questionName, questionType)
}
requestURL := fmt.Sprintf("%s?name=%s&type=%s", c.upstream, url.QueryEscape(questionName), url.QueryEscape(questionType))
+2 -1
View File
@@ -29,9 +29,10 @@ func main() {
bootstrap := flag.String("bootstrap", "", "The bootstrap DNS server to resolve the address of the upstream resolver")
timeout := flag.Uint("timeout", 10, "Timeout for upstream request")
noECS := flag.Bool("no-ecs", false, "Disable EDNS0-Client-Subnet, do not send client's IP address")
verbose := flag.Bool("verbose", false, "Enable logging")
flag.Parse()
client, err := NewClient(*addr, *upstream, *bootstrap, *timeout, *noECS)
client, err := NewClient(*addr, *upstream, *bootstrap, *timeout, *noECS, *verbose)
if err != nil { log.Fatalln(err) }
_ = client.Start()
}