Skip to content

Commit

Permalink
More logging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Aug 28, 2012
1 parent ca218b3 commit cbbf744
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 7 additions & 3 deletions log.go
Expand Up @@ -2,10 +2,14 @@ package main

import "log"

const NAME = "geodns: "

func logPrintf(format string, a ...interface{}) {
if *flaglog {
log.Printf(NAME+format, a...)
log.Printf(format, a...)
}
}

func logPrintln(a ...interface{}) {
if *flaglog {
log.Println(a...)
}
}
11 changes: 4 additions & 7 deletions serve.go
Expand Up @@ -21,18 +21,14 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *Zone) {
logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name,
dns.Rr_str[qtype], req.MsgHdr.Id, w.RemoteAddr())

if *flaglog {
log.Println("Got request", req)
}
logPrintln("Got request", req)

label := getQuestionName(z, req)

var country string
if geoIP != nil {
country = geoIP.GetCountry(w.RemoteAddr().String())
if *flaglog {
log.Println("Country:", country)
}
logPrintln("Country:", country)
}

m := new(dns.Msg)
Expand Down Expand Up @@ -66,7 +62,6 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *Zone) {
for _, record := range servers {
rr := record.RR
rr.Header().Name = req.Question[0].Name
log.Println(rr)
rrs = append(rrs, rr)
}
m.Answer = rrs
Expand All @@ -83,6 +78,8 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *Zone) {
}
}

logPrintln(m)

w.Write(m)
return
}
Expand Down

0 comments on commit cbbf744

Please sign in to comment.